Windows 服務安裝與卸載 (通過 Sc.exe)


1. 安裝

  • 新建文本文件,重命名為 ServiceInstall.bat,將 ServiceInstall.bat 的內容替換為:

sc create "Verity Platform Device Service" binPath= "%~dp0WindowsService_HardwareDevice.exe"

sc description "Verity Platform Device Service" "提供設備連接、FMC 電壓、PLL 時鍾、FPGA 配置、寄存器訪問等相關服務"

sc config "Verity Platform Device Service" start= AUTO

sc start "Verity Platform Device Service"

pause

 

注1:"Verity Platform Device Service" 為服務名;

注2:WindowsService_HardwareDevice.exe 為自己創建的用於承載 WCF 服務的的 Windows服務的安裝程序,創建方式如下:

     https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-a-managed-windows-service

  注3:pause 的作用為 .bat  運行完不退出,以查看運行結果(也可使用 @cmd.exe)。

 

  • 管理員身份運行 ServiceInstall.bat 完成 Windows 服務安裝。

 

2. 卸載

  • 新建文本文件,重命名為 ServiceUninstall.bat,將 ServiceUninstall.bat 的內容替換為:

sc stop "Verity Platform Device Service"

sc delete "Verity Platform Device Service" binPath= "%~dp0WindowsService_HardwareDevice.exe"

@cmd.exe

 

  • 管理員身份運行 ServiceUninstall.bat 完成 Windows 服務卸載。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM