(view source code of killprog.vbs as plain text)
' KillProg.vbs, Version 1.01' Kill a running program.'' Written by Rob van der Woude' http://www.robvanderwoude.com' Initialize variablesstrMsg = ""
numFound = 0
' Check command line parametersSelect Case WScript.Arguments.Count
Case 0
' At least a process should be specifiedSyntax
Case 1
' First parameter should be the process name ' or "/?" to request online helpstrP2k = Wscript.Arguments(0)
if InStr( strP2k, "?" ) > 0 Then Syntax
strComputer = "."
Case 2
' First parameter should be the process namestrP2k = Wscript.Arguments(0)
if InStr( strP2k, "?" ) > 0 Then Syntax
' Second parameter should be a computer namestrComputer = Wscript.Arguments(1)
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 2 command line parameterSyntax
End Select
On Error Resume Next
' Query and running processesSet objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicableIf Err.Number Then
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End If
On Error GoTo 0
' Kill specified processSet colItems = objWMIService.ExecQuery( "Select * from Win32_Process", , 48 )
For Each objItem in colItems
If LCase( objItem.Caption ) = LCase( strP2k ) Then
numFound = numFound + 1
Wscript.Echo "Terminating " & objItem.Caption
objItem.Terminate
End If
Next' Check if any process was foundIf numFound = 0 Then
WScript.Echo "No process named " & Chr(34) & strP2k & Chr(34) & " was found"
End If
' DoneWScript.Quit(0)
Sub SyntaxstrMsg = strMsg & vbCrLf & "KillProg.vbs, Version 1.01" & vbCrLf & _
"Terminate (" & Chr(34) & "kill" & Chr(34) & _
") a running program." & vbCrLf & vbCrLf & _
"Usage: CSCRIPT KILLPROG.VBS prog_name [ computer_name ]" & _
vbCrLf & vbCrLf & _
"Where: " & Chr(34) & "prog_name" & Chr(34) & _
" is the name of the program to be terminated" & vbCrLf & _
" " & Chr(34) & "computer_name" & Chr(34) & _
" is the name of the computer where " & Chr(34) & _
"prog_name" & Chr(34) & " is" & vbCrLf & _
" to be terminated" & _
vbCrLf & vbCrLf & _
"Written by Rob van der Woude" & vbCrLf & _
"http://www.robvanderwoude.com" & vbCrLf
WScript.Echo strMsg
' Abort with return code 1WScript.Quit(1)
End Sub
page last modified: 2025-10-11; loaded in 0.0214 seconds