天天看點

.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
           

繼續閱讀