Start Windows Service programmatically

后端 未结 6 2202
遥遥无期
遥遥无期 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条回答
  •  悲&欢浪女
    2020-12-08 00:38

    First of all you need to add reference of the DLL (ServiceProcess) in your project References as like:

    Right click on References in Solution Explorer -> Add Reference -> Assemblies -> 
    Framework -> System.ServiceProcess
    

    Then add ServiceProcess DLL in your project:

    using System.ServiceProcess;
    

    After that use this code:

    ServiceController service = new ServiceController(yourServiceName);
    

提交回复
热议问题