Windows 服务 安装后自启动

[RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();

            this.Committed += new InstallEventHandler(ProjectInstaller_Committed);
        }

        /// <summary>
        /// 安装完成后自启动服务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
        {
            ServiceController controller1 = new ServiceController("Service1");
            controller1.Start();
        }   
    }

 

posted @ 2019-04-10 14:05  OhMyJie  阅读(223)  评论(0编辑  收藏  举报