7

I am looking for a way to kill a windows services using its service name rather than the process name, or PID. The two obvious choices are pskill or taskkill, but I cannot seem to find a way of using either of these methods to kill the service by name.

Is it possible to do it by the service name? If so, is anyone able to provide a quick example?

ricky89
  • 1,326
  • 6
  • 24
  • 37
  • Perhaps this is what you are looking for `http://www.jasonn.com/enable_windows_services_command_line` – Nepal12 Dec 09 '14 at 09:22

4 Answers4

20

You can use taskkill to filter by service name and kill the service you're looking for.

taskkill /F /FI "SERVICES eq yourservice"
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
1

Do you actually want to KILL the process (e.g. if it is frozen) or do you want to STOP the service?

If you want to kill it stick to SomethingDark's answer (taskkill /F /FI "SERVICES eq yourservice").

If you want to stop it use SC STOP "servicename".

MichaelS
  • 5,941
  • 6
  • 31
  • 46
  • I wanted to kill it. I have a service that sometime cannot be stopped with NET STOP and in that instance need to kill it before restarting it. – ricky89 Dec 09 '14 at 10:08
1

In case you have multiple services with the same image name, using the SERVICES filter may not be sufficient. In this case, you need to use more filters like IMAGENAME, PID, STATUS or more.

See my related answer here

KatariaA
  • 752
  • 1
  • 7
  • 22
0

with taskkill loop (be careful with closing system processes) (save winservices.bat and run as admin)

call :winservices "service_name1"
call :winservices "service_name2"

:: funcion winservices
@echo off
 goto:eof
 :winservices
   set winservices=%1
     taskkill /f /im "%winservices%" /t
   goto:eof

source: https://serverfault.com/questions/1005487/how-to-stop-start-and-delete-a-windows-service-with-a-reference-to-the-service

acgbox
  • 312
  • 2
  • 13