Windows 服务安装与卸载 (通过 installutil.exe)

1. 安装

  • 安装 .NET Framework ;
  • 新建文本文件,重命名为 ServiceInstall.bat,将 ServiceInstall.bat 的内容替换为:

  C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "%~dp0WindowsService_HardwareDevice.exe"

  net start "Verity Platform Device Service"

  @cmd.exe  

  • 管理员身份运行 ServiceInstall.bat 完成 Windows 服务安装。

      

  注1:C:WindowsMicrosoft.NETFrameworkv4.0.30319 为.Net Framework 的安装路径;

  注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:@cmd.exe 的作用为 .bat  运行完不退出,以查看运行结果。

 

2. 卸载

  • 新建文本文件,重命名为 ServiceUninstall.bat,将 ServiceUninstall.bat 的内容替换为:

  C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /u  "%~dp0WindowsService_HardwareDevice.exe"

  @cmd.exe

  • 管理员身份运行 ServiceUninstall.bat 完成 Windows 服务卸载。
原文地址:https://www.cnblogs.com/dhqy/p/12049911.html