1.新建项目 --》 Windows 服务
2.Service1.cs代码
3.在Service1.cs设计页面右键添加安装程序
4.ProjectInstaller.cs设计页面中
serviceInstaller1属性中设置:
Description(系统服务的描述)
DisplayName (系统服务中显示的名称)
ServiceName(系统事件查看器里的应用程序事件中来源名称)
serviceProcessInstaller1属性设置:Account 下拉设置成 LocalSystem
5.在.net Framework的安装目录可以找到InstallUtil.exe,可以复制出来放在你的服务生成的exe一起
6.安装服务setup.bat批处理文件内容:InstallUtil Service1.exe ,安装好后可以在系统服务中找到你设置的服务名称然后可以启动这个服务
7.卸载服务UnInstall.bat批处理文件内容:InstallUtil -u Service1.exe