Automatically start a Windows Service on install

前端 未结 13 1369
轻奢々
轻奢々 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:57

    You can use the GetServices method of ServiceController class to get an array of all the services. Then, find your service by checking the ServiceName property of each service. When you've found your service, call the Start method to start it.

    You should also check the Status property to see what state it is already in before calling start (it may be running, paused, stopped, etc..).

提交回复
热议问题