94

I have created a windows service and in the service in control panel -> administrative tools -> services, its status is starting.

I want to stop this service, but the stop option is grayed out. How can I start/stop the service?

Every time I restart, then it becomes stopped and I can delete it.

Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

9 Answers9

160

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.

DrPppr242
  • 1,901
  • 1
  • 12
  • 7
  • 2
    Windows 2000 does not support `sc ..` So I located the process in properties of that service `Path to executable` and killed it in taskmgr. – A.D. Jul 04 '14 at 19:47
  • @DrPppr242, Are you sure this is a safe option? – Pacerier Feb 27 '15 at 20:38
  • 3
    The only way I got this to work was to run the command prompt as an Administrator. – hurleystylee Jul 07 '16 at 18:27
  • 3
    It doesn't work for the damn Baidu Hips Service. Even running cmd as Administrator. Sometimes I feel I'm not the owner of my own computer with this crappy OS... – Paulo Carvalho Mar 11 '17 at 13:51
  • This one works for sure. However, if you try to kill certain Windows services, you will get a BSOD stating that a critical process has died. Save your work before pressing Enter. – Alexandru Dicu Jul 13 '18 at 10:22
  • 2
    I tried this running CMD as admin. I get the following error: Unable to stop the process with PID XXXX. Reason: access denied. – Floppy88 Sep 12 '19 at 12:44
28

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

totev
  • 392
  • 3
  • 9
8

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:

  1. Boot into safe mode (Windows 10 users might need msconfig > boot > safe boot)
  2. Regedit into HKLM > System > ControlSet001 > Services
  3. Locate your service entry
  4. 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 !

vortal
  • 139
  • 2
  • 9
  • 1
    Great answer. It worked because the service wouldn't let me delete it, even with the PID. After editing the start key value and restarting, I was able to delete the service. Thank you. – Duque Sep 07 '19 at 16:20
  • What do I do if I am not allowed to change the permissions? I can't edit the start keyword in HKLM:\SYSTEM\CurrentControlSet\Services\WinDefend to 3 or 4 even when I open RegEdit as administrator. – Blaisem May 15 '21 at 14:46
  • At regedit, right-click the key name on the left pane, and choose Permissions. You should be able to upgrade the permissions being an admin. Then proceed as above. But being Windows Defender, it might be a little trickier to stop this thing. – vortal May 17 '21 at 14:50
8

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.

Aaron Klotz
  • 11,287
  • 1
  • 28
  • 22
2

Open command prompt with admin access and type the following commands there .

a)

tasklist

it displays list of all available services . There you can see the service you want to stop/start/restart . Remember PID value of the service you want to force stop.

b) Now type

taskkill /f /PID [PID value of the service] 

and press enter. On success you will get the message “SUCCESS: The process with PID has been terminated”.

Ex : taskkill /f /PID 5088

This will forcibly kill the frozen service. You can now return to Server Manager and restart the service.

2
sc queryex <service name>
taskkill /F /PID <Service PID>

eg

enter image description here

eg

1

I solved the problem with the following steps:

  1. Open "services.msc" from command / Windows RUN.

  2. Find the service (which is greyed out).

  3. Double click on that service and go to the "Recovery" tab.

  4. Ensure that

    • First Failure action is selected as "Take No action".
    • Second Failure action is selected as "Take No action".
    • Subsequent Failures action is selected as "Take No action".

    and Press OK.

Now, the service will not try to restart and you can able to delete the greyed out service from services list (i.e. greyed out will be gone).

Janugi Rama
  • 140
  • 1
  • 3
  • This sounds as good point but all options you suggest in my Win10 are greyed out. I'm stuck. Every time I stop the process (CyOptics) it starts again.... and it eats up >40% of my CPU :-( I did all tries with admin access – emare Nov 16 '20 at 09:34
0

Here's a simple method to kill a service you can't stop directly, if that service has dependencies.

  1. Open the service's properties window & click on dependencies tab
  2. See what it needs to run
  3. Stop one of those if possible, being sure that it won't also crash Windows

For example, stopping "network store interface service" aka nsi will kill an unkillable dnscache service. It will also kill all network capabilities & may require restarting Windows to get them back. I've had to do this to edit the hosts file, sometimes dnscache refuses to let go & you can't update hosts without killing it first but you can't do it directly.

AFOC
  • 699
  • 6
  • 15
0

The crucial thing that a lot of the suggestions dont make clear is that you must 'start command window as administrator' even if your already logged in as an administrator.

Chris Milburn
  • 862
  • 1
  • 12
  • 20