一、打开Visual Studio,创建项目->Windows 服务(.NET Framework)
二、点击Service.cs 点击切换到代码视图
三、点击Service.cs 在Service.cs设计视图中右击添加安装程序
四、会出现一个serviceProcessInstaller1和serviceInstaller1两个组件,serviceInstaller1属性中的ServiceName是服务名可以修改成自己的,把serviceProcessInstaller1属性中的Account改为LocalSystem
五、重新生成一下项目
六、在项目的bin\Debug文件夹下添加文本文档名为InstallService然后写上以下代码,替换为你的服务的实际路径,然后把文本文档的后缀名改成bat(这是安装服务,要以管理员启动),这样就可以在服务中看见你自己写的服务了
installutil C:\Users\34349\Desktop\Anomalymonitoring\bin\Debug\Anomalymonitoring.exe
pause
七、在项目的bin\Debug文件夹下添加文本文档名为Uninstall然后写上以下代码,替换为你的服务的实际路径,然后把文本文档的后缀名改成bat(这是卸载服务,要以管理员启动)
installutil C:\Users\34349\Desktop\Anomalymonitoring\bin\Debug\Anomalymonitoring.exe /u
pause
注意:这个服务不能启动winfrom这种可视化项目