http://blog.csdn.net/kerneliahou/archive/2008/02/29/2133087.aspx
1 創建新工程
file-->new-->project,選擇Visual C#-->Windows-->Windows Service
在service的OnStart()和OnStop()裏寫上代碼。
2 添加installer(必須,否則installutil無效,雖然指示安裝成功)
在service 的設計視圖中右鍵,選擇Add Installer,添加installer,VS自動添加ProjectInstaller.cs,並在其中添加serviceInstaller1和 serviceProcessInstaller1組件。在ProjectInstaller的設計視圖中選擇 serviceProcessInstaller1,修改他的Account屬性爲LocalSystem;同樣修改serviceInstaller1 的StartType屬性,設置服務啓動方式(手工、自動等)。
3 build你的project,生成service的exe文件
4 安裝
installutil service-exe-path
5 卸載
installutil /u service-exe-path