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批處理文件,如下用於安裝:
[html]
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
pause
如下用於卸載:
[html]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil d:\output\WindowsServiceTest.exe -u
pause
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil d:\output\WindowsServiceTest.exe -u
pause