Can a Windows service stop itself?

前端 未结 2 1266
清酒与你
清酒与你 2021-01-01 12:38

I have a Windows service whose startup type is automatic, but I want to do some checks when the service starts, and have the service stop automatically if these checks fail.

2条回答
  •  一整个雨季
    2021-01-01 13:08

    You can use ServiceController and call .stop.

    ServiceController sc= new ServiceController(service);
    sc.Stop();
    

提交回复
热议问题