(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 variables
strMsg = ""
numFound = 0
' Check command line parameters
Select Case WScript.Arguments.Count
Case 0
' At least a process should be specified
Syntax
Case 1
' First parameter should be the process name
' or "/?" to request online help
strP2k = Wscript.Arguments(0)
if InStr( strP2k, "?" ) > 0 Then Syntax
strComputer = "."
Case 2
' First parameter should be the process name
strP2k = Wscript.Arguments(0)
if InStr( strP2k, "?" ) > 0 Then Syntax
' Second parameter should be a computer name
strComputer = Wscript.Arguments(1)
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 2 command line parameter
Syntax
End Select
On Error Resume Next
' Query and running processes
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicable
If Err.Number Then
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End If
On Error GoTo 0
' Kill specified process
Set 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 found
If numFound = 0 Then
WScript.Echo "No process named " & Chr(34) & strP2k & Chr(34) & " was found"
End If
' Done
WScript.Quit(0)
Sub Syntax
strMsg = 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 1
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0101 seconds