首页 > Windows开发 > 详细

创建开机自动启动的.net windows服务

时间:2016-07-22 14:21:09      阅读:310      评论:0      收藏:0      [点我收藏+]

一、打开VS,新建项目,选择WINDOWS服务。

二、右击Service1.cs,添加安装程序。

三、右击serviceProcessInstaller1属性,Account设置为LocalSystem。

四、右击serviceInstaller1属性,ServiceName设置为服务名称(serviceName),StartType设置为Automatic。

五、F7进入后台,构造函数里增加事件

        public ProjectInstaller()
        {
            InitializeComponent();
            this.Committed += new InstallEventHandler(ProjectInstaller_Committed);   
        }

        private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
        {
            //参数为服务的名字
            System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController("serviceName");
            controller.Start();
        }   

 

创建开机自动启动的.net windows服务

原文:http://www.cnblogs.com/mr-yan/p/5694921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!