Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for killntpr2.bat

(view source code of killntpr2.bat as plain text)

  1. @ECHO OFF
  2. :: Keep variables local
  3. SETLOCAL
  4.  
  5. :: Explain usage if no parameter was given.
  6. IF "%1"=="" GOTO Syntax
  7. IF "%1"=="?" GOTO Syntax
  8. IF "%1"=="-?" GOTO Syntax
  9. IF "%1"=="/?" GOTO Syntax
  10.  
  11. :: Initialize main variable.
  12. SET PID=
  13.  
  14. :: Display which process is about to get killed.
  15. :: Lines with CMD.EXE are filtered out, because otherwise
  16. :: this batch file might accidently kill itself later.
  17. TLIST | FIND /I " %1 " | FIND /I /V "CMD.EXE"
  18.  
  19. :: Ask confirmation unless /Y parameter was specified.
  20. IF /I "%2"=="/Y" GOTO SkipConfirm
  21. ECHO Are you sure you want to kill this process?
  22. ECHO If not, press ^C (Ctrl+C), otherwise
  23. PAUSE
  24.  
  25. :SkipConfirm
  26. :: Find the process ID for the specified program
  27. FOR /F "tokens=1*" %%A IN ('TLIST ^| FIND /I " %1 " ^| FIND /I /V "CMD.EXE"') DO SET PID=%%A
  28.  
  29. :: Kill the process by its process ID.
  30. KILL %PID%
  31.  
  32. GOTO End
  33.  
  34. :Syntax
  35. :: Display help screen
  36. CLS
  37. ECHO KILLNTPR.BAT, Version 2.11
  38. ECHO KILL NT PRocess
  39. ECHO Written by Rob van der Woude
  40. ECHO http://www.robvanderwoude.com
  41. ECHO.
  42. ECHO Usage:  KILLNTPR  program_name  [ /Y ]
  43. ECHO.
  44. ECHO program_name is the file name of the executable
  45. ECHO              with extension but without path
  46. ECHO.
  47. ECHO /Y           if specified, no confirmation is required
  48. ECHO.
  49. ECHO This batch file uses some utilities from the MS Windows NT Resource Kit.
  50. ECHO It will not function without this Resource Kit.
  51.  
  52. :End
  53. ENDLOCAL
  54.  

page last uploaded: 2017-08-21, 14:26