1.新建项目
2.选择Windows服务
3.右击选择添加安装程序(此处也可从工具箱内脱出定时器)
4.选择serviceInstaller1,修改其相关属性
ProjectInstaller加入,其中有两个控件,选定“serviceInstaller1”,查看其属性,确认其ServiceName属性值为“OrderEmailSendDS”(即和第1步设定的项目名称相同),并把StartType属性设置为“Automatic”;这里有另外两个属性值要注意,分别是“DisplayName”和“Description”,分别是服务的显示名称及描述,这两个属性可以自行随意设置,Windows服务列表中显示的名称和描述即为这两个属性所制作。如果“DisplayName”为空(默认为空),则自动选定真实服务名(本例中为OrderEmailSendDS)为显示名称。
5.选择serviceProcessInstaller1,修改其相关属性
选定“serviceProcessInstaller1”,设置Account属性值为“LocalSystem”,LocalSystem是服务中的最高权限,其它权限相对低一些,相关内容可以查询资料;
6.编写OnStart和OnStop事件方法
7.点击生成
8.服务安装
以管理员身份启动命令窗口
找到“InstallUtil.exe”这个文件的绝对路径(一般在C:\Windows\Microsoft.NET\Framework64\v4.0.30319)和“OrderEmailSendDS.exe”你的服务存在路径(一般在你的项目文件中/bin/debug 文件夹里面)
安装指令:路径 InstallUtil.exe 路径 OrderEmailSendDS.exe(InstallUtil.exe F:\OrderEmailSendDS\OrderEmailSendDS\bin\Debug\OrderEmailSendDS.exe)
删除指令:路径 InstallUtil.exe /u 路径 OrderEmailSendDS.exe(InstallUtil.exe /u F:\OrderEmailSendDS\OrderEmailSendDS\bin\Debug\OrderEmailSendDS.exe)
9.查看安装(运行——services.msc),
附:
https://blog.csdn.net/love_pgme/article/details/82151416
https://www.cnblogs.com/youmingkuang/p/10069363.html
https://www.cnblogs.com/huangwei1992/p/9693167.html