搞个Windows服务程序

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”



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值