C# 安装和卸载 Windows Service

特别注意: 安装Window Service 的时候,一定要用管理员打开命令提示符(cmd)

1. 创建Windows Service 服务项目

2. Service设计界面:右键-->选择安装应用程序

生成serviceInstaller1和 serviceProcessInstaller1两个组件 
把serviceInstaller1的属性ServiceName改写为你的服务程序名,并把启动模 式设置为AUTOMATIC  
把serviceProcessInstaller1的属性account改写为 LocalSystem  

安装:

卸载:

切换到 InstallUtil.exe  所在目录下执行:installutil /u yourproject.exe

原文地址:https://www.cnblogs.com/yougmi/p/4933542.html