Automatically start a Windows Service on install

前端 未结 13 1361
轻奢々
轻奢々 2020-11-28 19:13

I have a Windows Service which I install using the InstallUtil.exe. Even though I have set the Startup Method to Automatic, the service does not start when installed, I have

13条回答
  •  醉酒成梦
    2020-11-28 19:38

    Programmatic options for controlling services:

    • Native code can used, "Starting a Service". Maximum control with minimum dependencies but the most work.
    • WMI: Win32_Service has a StartService method. This is good for cases where you need to be able to perform other processing (e.g. to select which service).
    • PowerShell: execute Start-Service via RunspaceInvoke or by creating your own Runspace and using its CreatePipeline method to execute. This is good for cases where you need to be able to perform other processing (e.g. to select which service) with a much easier coding model than WMI, but depends on PSH being installed.
    • A .NET application can use ServiceController

提交回复
热议问题