Skip navigation

JSI Tip 4010. How do I kill a process in a batch file, if it is running?


To kill a process in a batch file, you can determine if it is running by parsing the output of PuList. Extract the PID and use Kill from the Windows 2000 Support Tools, or the Windows NT 4.0 Resource Kit.

I have scripted Killproc.bat which can be used with the following syntax:

Killproc <Process>

Example: To kill Microsoft Word, if it is running: call Killproc Winword.exe

NOTE: The batch is not case sensitive.

Killproc.bat contains:

@echo off
setlocal
set proc=%1
for /f "Skip=3 Tokens=1,2" %%i in ('pulist') do call :myproc %%i %%j
endlocal
goto :EOF
:myproc
If /i NOT "%1" EQU "%proc%" goto :EOF
Kill /f %2
NOTE: If you do not have Kill.exe, replace Kill /f %2 with pskill %2.


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish