Restarting a Stuck Service

From time to time, you might find yourself in a position where you need to restart a service that’s stuck in a “starting” or “stopping” state. While this is happening, you won’t be able to interact with the service via the Services Management Console (services.msc).

Before you can kill the stuck process, you have to have know what the ID is. To do this, run sc queryex from the command prompt. Doing this can return a lot of results, so I like to pipe them into a text file for easy viewing/searching:

sc queryex > processes.txt

Once completed, open it in a text editor to find your process:

notepad processes.txt

Looking at the file, you’ll see a list of your services and what state their in. You should be able to locate the stuck service by name:

DISPLAY_NAME: Some Application Service Service
        TYPE               : 20  WIN32_SHARE_PROCESS
	STATE              : 4  RUNNING                                 
	WIN32_EXIT_CODE    : 0  (0x0)
	SERVICE_EXIT_CODE  : 0  (0x0)
	CHECKPOINT         : 0x0
	WAIT_HINT          : 0x0
	PID                : 1527
	FLAGS              :

The specific fields to pay attention to are DISPLAY_NAME (friendly name of the service), STATE (running, stopped, starting, stopping etc.), and PID (Process ID).

The PID is especially important because we need it to determine what process to kill. In the example above, the PID is 1527, we’ll use this number in the next command, TASKKILL:

taskkill /PID 1527 /F

Just as the name implies, TASKKILL ends tasks or processes. You can find a more detailed explanation along with syntax and parameters on TechNet.

Leave a Reply

Your email address will not be published. Required fields are marked *