I have a batch file which uses taskkill
to stop several services. The commands look like this:
taskkill /s \\myServer /f /fi "Services eq MyService"
The problem is that each command takes a really long time (around 1 minute). Since there are several such commands, the batch file is really slow.
Is there any way to speed up taskkill
?
Try using
sc stop
instead of killing the service. It's a preferred method.http://technet.microsoft.com/en-us/library/cc742107(WS.10).aspx
In addition to what @pk said, if you must use taskkill, you could create one bat file for each task to kill, then create a bat file to call each batch file.
Would still be slow for each taskkill to finish, but they would run at the same time, speeding up your full script.
Should look something like this:
I tried switching to
sc
but it was also very slow. There is some underlying issue (possibly networking related?) but I haven't been able to find it.I ended up moving the service stopping code to a .vbs script using WMI using the info here.