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.
How can I do this? My service is written in C#.
Once the win service is started then this process will run continuously in background.
Look in the event log: The service control manager logs every time a service is stopped or started. This is Event Viewer -> Windows Logs -> System, where Source is Service Control Manager.
When a service is paused, it can maintain internal state, including cached information or possibly even a queue of waiting work items. The service can then be resumed to pick up where it left off. If the service is stopped, internal state is discarded.
You can call the Stop
method on your ServiceBase
class. See msdn for more details.
You can use ServiceController and call .stop.
ServiceController sc= new ServiceController(service); sc.Stop();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With