Windows Service 學習系列(二):C# windows服務:安裝、解除安裝、啟動和停止Windows Service
一、通過CMD安裝、解除安裝、啟動、停止Windows Service
方法一
1.以管理員身份執行cmd
2.安裝windows服務
切換cd C:\Windows\Microsoft.NET\Framework\v4.0.30319(InstallUtil.exe的路徑下,注意InstallUtil.exe的版本號需要和專案的版本號相同)
3.安裝windows服務
InstallUtil.exe D:\SimpleService\SimpleService\bin\Debug\SimpleService.exe(專案的路徑)
(安裝過程中出現的錯誤:Window Service Install "帳戶名無效或不存在,或者密碼對於指定的帳戶名無效。" 解決方法:填使用者名稱時,要在前面加上 .\)
4.啟動windows服務
net start Servive1(服務名稱)
5.解除安裝windows服務
InstallUtil.exe /u D:\SimpleService\SimpleService\bin\Debug\SimpleService.exe
方法二
1、找到 Installutil.exe 檔案,並把它複製到 D:\SimpleService\SimpleService\bin\Debug\目錄
2、現在 Installutil.exe 程式在 D:\SimpleService\SimpleService\bin\Debug 目錄下,需要通過cmd命令 "cd" 切換到該目錄下。
3、安裝服務:
installutil.exe SimpleService.exe
4、解除安裝服務:
installutil.exe SimpleService.exe
二、通過程式安裝、解除安裝、啟動、停止Windows Service