安裝服務
第一種:
- 點選 開始,運作中輸入cmd
- 輸入
回車cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
注意:在C:\Windows\Microsoft.NET\Framework目錄下有很多類似版本,具體去哪個目錄要看項目的運作環境,例 如果是.net framework2.0則需要輸入 cd C:\Windows\Microsoft.NET\Framework\v2.0.50727
- 輸入
回車InstallUtil.exe D:\Service.exe
說明:D:\Service.exe 需要安裝的windows服務exe檔案位置
- 打開服務,就可以看到已經安裝的服務了
第二種
- 點選 開始,運作中輸入cmd
- 輸入
sc create Service binpath= "D:\Service.exe" displayname= "Service" depend= Tcpip start= auto
說明: sc create 服務名稱 binpath= “檔案位置” displayname= “顯示名稱” depend= Tcpip start= auto (啟動類型)
第三種
- 建立文本檔案,重命名為 ServiceInstall.bat,将 ServiceInstall.bat 的内容替換為:
sc create "Service" binPath= "D:\Service.exe" displayname= "Service" depend= Tcpip start= auto
sc start "Service"
pause
說明:pause 的作用為 .bat 運作完不退出,以檢視運作結果(也可使用 @cmd.exe)。
- 以管理者身份運作 ServiceInstall.bat 完成 Windows 服務安裝。
解除安裝服務
第一種
- 點選 開始,運作中輸入cmd
- 輸入
回車,切換目錄cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
- 輸入
回車,解除安裝服務InstallUtil.exe /u D:\Service.exe
第二種
- 點選 開始,運作中輸入cmd
- 輸入
sc delete "Service" binPath= "D:\Service.exe"
說明:sc delete “服務名稱” binPath= “檔案位置”
第三種
- 建立文本檔案,重命名為 ServiceUninstall.bat,将 ServiceUninstall.bat 的内容替換為:
sc delete "Service" binPath= "D:\Service.exe"
@cmd.exe
- 以管理者身份運作 ServiceUninstall.bat 完成 Windows 服務解除安裝。