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.
You can use ServiceController and call .stop.
ServiceController sc= new ServiceController(service); sc.Stop();