1 2 | Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "programma.exe" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | ' 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 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 |
1 | ...vbs "naamvanprogramma.ext" |
1 2 | Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "programma.exe" |
|
Forum Opties | |
---|---|
Forumhop: | |
Hop naar: |