Start stop Service from Form App c#

后端 未结 5 1944
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 19:11

How can I start and stop a windows service from a c# Form application?

5条回答
  •  不知归路
    2020-12-04 20:06

    You can do it like this, Details of Service Controller

    ServiceController sc = new ServiceController("your service name");
    if (sc.Status == ServiceControllerStatus.Stopped)
    {
      sc.Start();
    
    }
    

    Similarly you can stop using stop method

      sc.Stop();
    

提交回复
热议问题