Breaking News

Force stopping MySQL service / Killing a process related to a service


I the last days I face a problem which is some service never stops while is should be stopped. So I tried to get the ralated Process ID PID and kill this process.

you can manage the service in the windows through the SC command type this to see the help

SC /? | more

You can query or alter the status of the service .. for example if you want to get some info about a specific service check this result

C:\>sc queryex MySQL
SERVICE_NAME: MySQL
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 3  STOP_PENDING
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 7473
        FLAGS              :


The info that we care about is the STATE and PID ..
The problem is it tried to stop the service but it does not stoped !!

SC stop MySQL

so I thought that if  I got the related process and killed it .. the service in this case is stopped.
So this what I did .. i tried to stop the service normally and wait some seconds ..
Then I get the related Process ID and force killing it with TASKKILL command
Type this for more details  taskkill /?

And here is the final code ..

This code is written for windows:
sc stop MySQL
for /f "tokens=2 delims=[:]" %%f in ('sc queryex MySQL ^|find /i "PID"') do set PID=%%f
taskkill /f /pid %PID%


I hope this could help you.

Thanks a lot.

Your's Moataz Mohamed

From My Friend Blogger 

No comments