码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-07-22 14:22:12      阅读:262      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!