1、新建项目=======》Visualc#.windows======>windows服务====》新建完成 (服务项目名称自取)
2、打开Service1.cs======》右击添加安装程序======》=========》在查看S而vice1的代码======》
=====>编写代码即可
3、安装服务
用.net framework工具INSTALLUTIL安装服务程序即可。
用项目的输出作为参数,从命令行运行 InstallUtil.exe。在命令行中输入下列代码:
installutil yourproject.exe
Hint: a windows service must first be installed using installutil.exe and then started with the serviceExplorer, windows Services Administrative tool or the NET START command.
4、卸载服务
用项目的输出作为参数,从命令行运行 InstallUtil.exe。
installutil /u yourproject.exe
补充
1.Service启动属性:
Manual 服务安装后,必须手动启动。
Automatic 每次计算机重新启动时,服务都会自动启动。
Disabled 服务无法启动。
2.新建的Service项目,其中各属性的含义(设计视图->右键属性):
Autolog 是否自动写入系统的日志文件
CanHandlePowerEvent 服务时候接受电源事件
CanPauseAndContinue 服务是否接受暂停或继续运行的请求
CanShutdown 服务是否在运行它的计算机关闭时收到通知,以便能够调用 OnShutDown 过程
CanStop 服务是否接受停止运行的请求
ServiceName 服务名
调试Windows Service
1)安装并运行服务
2)附加进程
3)在代码中加入断点进行调试