How to automatically start your service after install?

前端 未结 7 1216
小蘑菇
小蘑菇 2020-12-05 01:50

How do you automatically start a service after running an install from a Visual Studio Setup Project?

I just figured this one out and thought I would share the answe

7条回答
  •  独厮守ぢ
    2020-12-05 02:30

    Based on the snippets above, my ProjectInstaller.cs file wound up looking like this for a service named FSWServiceMgr.exe. The service did start after installation. As a side note, remember to click on the Properties tab (not right-click) when the setup project is selected in the Solution Explorer to set the company and so forth.


    using System.ComponentModel;
    using System.Configuration.Install;
    using System.ServiceProcess;
    
    namespace FSWManager {
        [RunInstaller(true)]
        public partial class ProjectInstaller : Installer {
            public ProjectInstaller() {
                InitializeComponent();
                this.FSWServiceMgr.AfterInstall += FSWServiceMgr_AfterInstall;
            }
    
            static void FSWServiceMgr_AfterInstall(object sender, InstallEventArgs e) {
                new ServiceController("FSWServiceMgr").Start();
            }
        }
    }
    

提交回复
热议问题