Stopping a windows service when the stop option is grayed out
If you run the command:
sc queryex <service name>
where is the the name of the service, not the display name (spooler, not Print Spooler), at the cmd prompt it will return the PID of the process the service is running as. Take that PID and run
taskkill /F /PID <Service PID>
to force the PID to stop. Sometimes if the process hangs while stopping the GUI won't let you do anything with the service.
You could do it in one line (useful for ci-environments):
taskkill /fi "Services eq SERVICE_NAME" /F
Filter -> Services -> ServiceName equals SERVICE_NAMES -> Force
Source: https://technet.microsoft.com/en-us/library/bb491009.aspx
If the stop option is greyed out then your service did not indicate that it was accepting SERVICE_ACCEPT_STOP
when it last called SetServiceStatus
. If you're using .NET, then you need to set the CanStop
property in ServiceBase
.
Of course, if you're accepting stop requests, then you'd better make sure that your service can safely handle those requests, especially if your service is still progressing through its startup code.
Use the Task manager to find the Service and kill it from there using End Task. Always does the trick for me.
If you have made the service yourself, consider removing Long running operations from the OnStart event, usually that is what causes the Service to be non responsive.
As Aaron mentioned above, some services do not accept SERVICE_ACCEPT_STOP
messages, by the time it was developed. And that is hard coded into the executable. Period. A workaroud would be not to have it started, and as you cannot change its properties, forcibly do the following:
- Boot into safe mode (Windows 10 users might need msconfig > boot > safe boot)
- Regedit into HKLM > System > ControlSet001 > Services
- Locate your service entry
- Change 'Start' key to 3 (manual startup) or 4 (disabled)
If you cannot change the entry, right-click on your service name on the left pane, select 'Permissions', check that 'Everyone' has full access and try step 4 again.
Don't forget to disable safe boot from msconfig again, and reboot !