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

前端 未结 8 1320
再見小時候
再見小時候 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:46

    Use the .NET ServiceController class to start it, or issue the commandline command to start it --- "net start servicename". Either way works.

    0 讨论(0)
  • 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.

    <ServiceInstall 
        Id="ServiceInstaller"  
        Type="ownProcess"  
        Vital="yes"  
        Name=""  
        DisplayName=""  
        Description=""  
        Start="auto"  
        Account="LocalSystem"   
        ErrorControl="ignore"   
        Interactive="no">  
            <ServiceDependency Id="????"/> ///Add any dependancy to your service  
    </ServiceInstall>
    
    0 讨论(0)
提交回复
热议问题