How to make a .NET Windows Service start right after the installation?

前端 未结 8 1569
再見小時候
再見小時候 2020-11-22 10:49

Besides the service.StartType = ServiceStartMode.Automatic my service does not start after installation

Solution

Inserted this code on my Pr

8条回答
  •  眼角桃花
    2020-11-22 11:49

    Visual Studio

    If you are creating a setup project with VS, you can create a custom action who called a .NET method to start the service. But, it is not really recommended to use managed custom action in a MSI. See this page.

    ServiceController controller  = new ServiceController();
    controller.MachineName = "";//The machine where the service is installed;
    controller.ServiceName = "";//The name of your service installed in Windows Services;
    controller.Start();
    

    InstallShield or Wise

    If you are using InstallShield or Wise, these applications provide the option to start the service. Per example with Wise, you have to add a service control action. In this action, you specify if you want to start or stop the service.

    Wix

    Using Wix you need to add the following xml code under the component of your service. For more information about that, you can check this page.

      
             ///Add any dependancy to your service  
    
    

提交回复
热议问题