Can a Windows service stop itself?

前端 未结 2 1263
清酒与你
清酒与你 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 call the Stop method on your ServiceBase class. See msdn for more details.

    0 讨论(0)
  • 2021-01-01 13:08

    You can use ServiceController and call .stop.

    ServiceController sc= new ServiceController(service);
    sc.Stop();
    
    0 讨论(0)
提交回复
热议问题