Start Windows Service programmatically

后端 未结 6 2188
遥遥无期
遥遥无期 2020-12-08 00:02

I am having an issue with an application that I am creating. I am trying to start a windows service through my C# app. When I click my start button, it looks like everythi

6条回答
  •  -上瘾入骨i
    2020-12-08 00:54

    If the code you showed is executing on a different machine than where the service is supposed to run (I'm not clear from your comments if that's the case or not), you would need to provide the machine name in the ServiceController constructer.

    Is it possible you are successfully starting the service, but not on the machine you think? That would fit the symptoms you describe.

    ServiceController service = new ServiceController(serviceName, serverName);
    

    Also see ServiceController constructor documentation.

提交回复
热议问题