Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for killntpr.bat

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

  1. @ECHO OFF
  2. :: KILLNTPR.BAT, Version 1.03
  3. :: KILL NT PRocess by its executable file name
  4. :: Written by Rob van der Woude
  5. :: http://www.robvanderwoude.com
  6. :: Dependencies: [1] MS Windows NT Resource Kit
  7. ::               [2] ENGLISH version of NT
  8.  
  9. :: Explain usage if no parameter was given.
  10. IF "%1"=="" GOTO Syntax
  11. IF "%1"=="?" GOTO Syntax
  12. IF "%1"=="-?" GOTO Syntax
  13. IF "%1"=="/?" GOTO Syntax
  14.  
  15. :: Initialize main variable.
  16. SET PID=
  17.  
  18. :: Display which process is about to get killed.
  19. :: Lines with CMD.EXE are filtered out, because
  20. :: otherwise this batch file might accidently
  21. :: kill itself later.
  22. TLIST | FIND /I " %1 " | FIND /I /V "CMD.EXE"
  23.  
  24. :: Ask confirmation unless /Y parameter was specified.
  25. IF "%2"=="/Y" GOTO SkipConfirm
  26. IF "%2"=="/y" GOTO SkipConfirm
  27. ECHO Are you sure you want to kill this process?
  28. ECHO If not, press ^C (Ctrl+C), otherwise
  29. PAUSE
  30.  
  31. :SkipConfirm
  32. :: Redirect the line we just displayed to a temporary batch file.
  33. :: By first feeding the line to TIME, we make sure the displayed
  34. :: line will be preceded by a fixed string (Enter the new time:),
  35. :: which makes it easier to store the FIRST word in the line (the
  36. :: process ID) in an environment variable PID.
  37. TLIST | FIND /I " %1 " | FIND /I /V "CMD.EXE" | TIME | FIND /I "%1" > TEMP.BAT
  38.  
  39. :: Create another temporary batch file, ENTER.BAT.
  40. :: IMPORTANT: The string "Enter the new time:" is, of course,
  41. ::            language dependant, so modify and rename this batch
  42. ::            file accordingly if you use a non-English NT version.
  43. >  ENTER.BAT ECHO @ECHO OFF
  44. >> ENTER.BAT ECHO SET PID=%%4
  45.  
  46. :: Now call TEMP.BAT, which in turn call ENTER.BAT, which sets the
  47. :: value of environment variable PID to the wanted process ID.
  48. CALL TEMP.BAT
  49.  
  50. :: Kill the process by its process ID.
  51. KILL %PID%
  52.  
  53. :: Clean up the mess.
  54. DEL ENTER.BAT
  55. DEL TEMP.BAT
  56. SET PID=
  57.  
  58. :: And quit.
  59. GOTO End
  60.  
  61. :Syntax
  62. :: Display help screen
  63. CLS
  64. ECHO KILLNTPR.BAT, Version 1.03
  65. ECHO KILL NT PRocess
  66. ECHO Written by Rob van der Woude
  67. ECHO http://www.robvanderwoude.com
  68. ECHO.
  69. ECHO Usage:  KILLPRNT  program_name  [ /Y ]
  70. ECHO.
  71. ECHO program_name is the file name of the executable
  72. ECHO              with extension but without path
  73. ECHO.
  74. ECHO /Y           if specified, no confirmation is required
  75. ECHO.
  76. ECHO This batch file uses some utilities from the MS Windows NT Resource Kit.
  77. ECHO It will not function without this Resource Kit.
  78.  
  79. :: Modify or remove the next command line if you
  80. :: adapted this batch file to any other language.
  81. ECHO This batch file was written for English NT versions only.
  82.  
  83. :End
  84.  

page last modified: 2024-04-16; loaded in 0.0206 seconds