天天看点

.net windows service开发与安装

1、创建一个Windows Service项目名为WindowsServiceTest;

2、添加一个Windows Service项名为TestService.cs;

3、实现TestService类的OnStart和OnEnd;

4、右键点击TestService的设计视图,选择右键菜单项Add Installer,vs自动创建一个ProjectInstaller.cs类,ProjectInstaller.cs中自动附带了两个serviceInstaller1和serviceProcessInstaller1成员;(在serviceInstaller1和serviceProcessInstaller1中根据实际设置启动帐户和启动方式)

5、Build完成,创建一个install.bat批处理文件,如下用于安装:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil d:\output\WindowsServiceTest.exe

pause
           

如下用于卸载:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil d:\output\WindowsServiceTest.exe -u

pause
           

继续阅读