Windows服务开发笔记

时间:2019-11-06
本文章向大家介绍Windows服务开发笔记,主要包括Windows服务开发笔记使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1,服务程序框架需和发布工具InstallUtil版本一致;

2,InstallUtil一般随VisualStudio安装而安装,在C:\Windows\Microsoft.NET\Framework路劲的对应版本号目录下;

3,一个Windows服务程序可以加载多个服务,在Main方法中添加即可;

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
 {
    new Service1(),
    new Service2()
};
ServiceBase.Run(ServicesToRun);

4,Windows服务程序需添加安装程序[ProjectInstaller],可据服务个数创建相应的安装服务对象,并自定义名称,如:

this.serviceInstaller1.Description = "TEST SERVICE";
this.serviceInstaller1.ServiceName = "Service1";

5,安装过后的服务可根据设定的ServiceName去Windows服务中查找;

6,使用InstallUtil安装服务程序(exe)时,会要求输入账号密码,测试时可默认为:

this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceProcessInstaller1.Account = ServiceAccount.LocalService;//添加这行

原文地址:https://www.cnblogs.com/shawsir/p/WindowsServiceNotes.html