batch - How to stop a bat process on Windows?
2013-12
I have BAT file running in background on Windows which lasts about ten minutes. Now I want to stop it while it's running, but I can't find its name in the process-list in the task manager. So how can I approach this? Thanks!
UPDATE1
It seems difficult to stop a running BAT process in backgroud.And I decide to try to kill every process involved by the BAT file by name,which may be overkilled.It's acceptable to me since most processes in my BAT file are not used frequently,such as ping,tracert,netstat etc.If you have any better solution please let me know.Thanks.
UPDATE2
BAT process tree
Processes usually get launched in a tree like fashion, I would advise launching Microsoft / Sysinternals Process Explorer, Start by clicking on the Show Process Tree
(1) option, then find your process and right click and choose Kill Process Tree
(2) This should kill both the original file and everything that it has launched.
You can modify the batch file so that it uses a lock-file to continue operating, by inserting checks between commands for the existence of the file. To stop the batch file from executing, just delete the lock-file.
Here is a demo batch file:
echo xx > "c:\temp\lockfile"
pause
if not exist "c:\temp\lockfile" goto exit
pause
del "c:\temp\lockfile"
:exit
To violently kill the processes that might be executing at the moment, you can create a 'kill' batch file that will contain taskkill commands for all the tasks possibly launched from the batch file:
del "c:\temp\lockfile"
taskkill /im mytask1.exe
taskkill /im mytask2.exe
A BAT typically just launches an instance of CMD.exe. Depending on what your script does, it will also start other processes.
I wrote an app that might help you, at least if the BAT is running in a CMD window. You can view the application windows that are running and get the PID of the app, you can then kill it with my app, you can also see all the processes that it has spawned and kill them too. Its a real simple program, but effective for this sort of thing. You can also use it to track down exactly where on your HD the BAT file is running from, in case you didn't know that already.
How is the batch file invoked?
If it is from the Task Scheduler, then you can stop it from there as well. If it is from a service, then you can stop the service.
Found this message board thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=261694
It suggests using ShellExecuteEx (or CreateProcess)so you can get a process handle, that then can be used to kill the process.
How can I kill a process from the command prompt on Windows NT? Preferably with a tool that comes with the operating system.
If you had XP or later you could use TASKKILL
. This on not NT though.
I think you're going to have to download something to do this. I'd recommend pskill
from Sysinternals.
You can use this either with a process ID or just with a process name. For example:
pskill notepad.exe
Another option is KILL
from the NT Resource Kit.
To kill process with children (like apache), from Windows XP to Windows Seven :
TASKKILL /T /F /PID 4520
There are a couple of choices:
KILL Command
kill process name or id
or
kill -f process name or id
AT Utility
at time /interactive cmd /c kill -f process name or id
And of course
Reboot :-)