Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for killprog.cmd

(view source code of killprog.cmd as plain text)

  1. /* KILLPROG, Version 1.01                   */
  2. /* Kill process by its executable file name */
  3. /* Written by Rob van der Woude             */
  4. /* http://www.robvanderwoude.com            */
  5.  
  6.  
  7. /* Check command line parameters */
  8. parse upper arg exec"/"options
  9. exec    = strip( exec )
  10. options = strip( options )
  11. if exec = ""  then call Syntax
  12. exactmatch = 0
  13. confirm    = 1
  14. if options <> "" then do
  15. 	if pos( "?", options ) > 0 then call Syntax
  16. 	if pos( "X", options ) = 0 & pos( "Y", options ) = 0 then call Syntax
  17. 	parse value options with option1"/"option2
  18. 	option1 = strip( option1 )
  19. 	option2 = strip( option2 )
  20. 	if option1 = "X" | option2 = "X" then exactmatch = 1
  21. 	if option1 = "Y" | option2 = "Y" then confirm    = 0
  22. end
  23.  
  24. /* Initialize RexxUtil */
  25. if RxFuncQuery( "SysLoadFuncs" ) <> 0 then do
  26. 	call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  27. 	call SysLoadFuncs
  28. end
  29.  
  30. /* Initialize Quercus System's RexxLib */
  31. if RxFuncQuery( "RexxLibRegister" ) <> 0 then do
  32. 	call RxFuncAdd "RexxLibRegister", "rexxlib", "RexxLibRegister"
  33. 	call RexxLibRegister
  34. end
  35.  
  36. pid.0 = DOSPIDLIST( pid, name, parent, session )
  37. if pid.0 > 0 then do i = 1 to pid.0
  38. 	if ( exactmatch = 0 & pos( exec, name.i ) > 0 ) | ( exactmatch = 1 & exec = name.i ) then do
  39. 		if confirm = 1 then do
  40. 			say "Process ID   = "||pid.i
  41. 			say "Program name = "||name.i
  42. 			say "Parent       = "||parent.i
  43. 			say "Session ID   = "||session.i
  44. 			say
  45. 			say "Are you sure you want to kill this process?"
  46. 			call SysCurState "OFF"
  47. 			answer = translate( SysGetKey( "NOECHO" ) )
  48. 			if answer <> "Y" then iterate
  49. 		end
  50. 		rc = DOSKILLPROCESS( pid.i, "P" )
  51. 		if rc = 1 then do
  52. 			say "Successfully killed process "||pid.i
  53. 		end
  54. 		else do
  55. 			call beep 220, 240
  56. 			say "Error trying to kill process "||pid.i
  57. 		end
  58. 	end
  59. end
  60. EXIT 0
  61.  
  62.  
  63. Syntax: procedure
  64. 	say
  65. 	say "KILLPROG,  Version 1.01"
  66. 	say "Kill a process by its executable name"
  67. 	say "Written by Rob van der Woude"
  68. 	say "http://www.robvanderwoude.com"
  69. 	say
  70. 	say "Usage:  KILLPROG  file_name.ext  [ /Y ]"
  71. 	say
  72. 	say "filename.ext is the executable's file name"
  73. 	say
  74. 	say "With /Y specified, the program will not ask for confirmation"
  75. 	say
  76. 	say "WARNING: This is an extremely powerful program, that"
  77. 	say "         has the potential to destroy your data!"
  78. 	say "         Use entirely at your own risk!"
  79. 	say "         Do not use unless you understand its function!"
  80. 	EXIT 9
  81. return
  82.  

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