当前位置:首页 > 操作系统 > Windows

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 服务安装。

 

 

 

原文:https://www.cnblogs.com/dhqy/p/12082555.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐