Use VBS script to “kill” a process on a remote server

You can use this VBS script to kill a running process on your local machine or a remote one. As a performance tester, I have found this useful since it allows me to kill the Mercury Agent Process (magentproc.exe) on remote LoadRunner generators.

Save the text below as a file called “ProcessKill.vbs” and run it to kill the agent process on your own machine.  You just need to change the strProcessKill and strComputer strings to determine the process that you want to kill and the machine where you want to kill it. By default the script runs on the local machine “.”

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = “.”
strProcessKill = “‘magentproc.exe'”

Set objWMIService = GetObject(“winmgmts:” _& “{impersonationLevel=impersonate}!” & strComputer & “rootcimv2”)

Set colProcess = objWMIService.ExecQuery _(“Select * from Win32_Process Where Name = ” & strProcessKill )

For Each objProcess in colProcess
WSCript.Echo “Just killed process ” & strProcessKill _& ” on ” & strComputer

Author: Richard Bishop