windows服务程序方便,可以自动启动,也不受登录用户影响。没有界面,不大方便,但也有好处,眼不见心不烦。
说说它怎么安装:
1、添加一个项:安装程序类
2、在这个安装程序页面上添加两个组件ServiceInstaller,ServiceProcessInstaller,并设置
3、编译好的exe要用InstallUtil.exe来进行安装。
installUtil.exe为windows自带,搜一下就能得到。
命令格式为:installutil ***.exe
这里记得待安装的服务程序一定要写全称,就是要带后缀。
代码部分,要在program写一点东西才能启动:
using System.ServiceProcess; class Program { static void Main(string[] args) { ServiceBase[] ServicesToRun; // 同一进程中可以运行多个用户服务。若要将 // 另一个服务添加到此进程中,请更改下行以 // 创建另一个服务对象。例如, // // ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()}; // ServicesToRun = new ServiceBase[] { new Catch() }; ServiceBase.Run(ServicesToRun); } }安装的时候,如果提示
“安装因缺少 ServiceProcessInstaller而失败”,
可以改 this.Installers.AddRange(new System.Configuration.Install.Installer[] {this.serviceInstaller1,this.serviceProcessInstaller1}); 少了“this.serviceProcessInstaller1”