A Process Killer

Sometime your Windows computer got a virus and you can’t show process inside using task manager. But you may check process list and kill one of them. Or you are an network administrator and want to check process running on client computer. There’s a way to show process list and kill them. It’s use objWMIServices object by vbscript.
This is an example how to use objWMIServices object. Just copy it in notepad, save as killprocess.vbs and run it :

ArrstrComputerName = Array(“.”)
userName = Array(“.”)
passWord = Array(“.”)
‘ArrstrComputerName = Array(“192.168.0.4″,”.”) ‘ array of computer name
‘userName = Array(“192.168.0.3\admin”,”.”) ‘ array of username , for localhost we needn’t it but fill with empty string
‘passWord = Array(“1234″,”.”) ‘ array of password , for localhost we needn’t it but fill with empty string
str = “”
For Each strComputerName in ArrstrComputerName
str = str + vbNewLine + “-“+strComputerName

Next

str = “Running this application sometime will take long time.”+vbNewLine+”Wait until script show message ‘Finished’ mean this script have do all job “+ vbNewLine +”This application will check process on ” + str+ vbNewLine+ “Continue Anyway ?”
y= MsgBox (str,vbOKCancel)
If(y=vbOK) Then

jC = UBound(ArrstrComputerName)+1
ix=0
perpage =20
Dim arrayListProcess()
Dim arrayNameProcess()
Dim arrayUserProcess()
Dim objProcessList
Dim listProcessId
listProcessId=””
On Error Resume Next
For Each strComputerName in ArrstrComputerName
Set objProcessList = Nothing

If strComputerName = “.” Or strComputerName = “localhost” Or strComputerName = “127.0.0.1” Or strComputerName = “” Then
‘ if process in local computer
Set objWMIServices = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputerName & “\root\cimv2”)
Set objProcessList = objWMIServices.ExecQuery(“SELECT * FROM Win32_Process “)
Else
‘process in remote computer
Set objSWbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputerName, “root\cimv2”, userName(ix), passWord(ix))
Set objProcessList = objSWbemServices.ExecQuery(“Select * From Win32_Process “)
End If
‘WScript.Sleep 1000
If TypeName(objProcessList)<>”Nothing” Then
‘ if remote computer connected

ReDim arrayListProcess(1)
i=0
For Each objProcess in objProcessList
i=i+1
Redim Preserve arrayListProcess(i)
Redim Preserve arrayNameProcess(i)
Redim Preserve arrayUserProcess(i)

set objUsers = objProcess.ExecMethod_(“GetOwner”)
user = objUsers.User
if(IsNull(user))Then user = “”
arrayListProcess(i) = objProcess.ProcessId
arrayNameProcess(i) = objProcess.Name
arrayUserProcess(i) = user
‘listProcessId = listProcessId+CStr(i)+”-“+ + CStr(objProcess.ProcessId)+ “-” + CStr(objProcess.Name)+”-” + CStr(user) + vbNewLine
Next
‘WScript.Echo i

If(i>0)Then
jpage = Round(i/perpage+0.5)
‘MsgBox(Cint(i/perpage))
For ji = 0 To jpage -1

‘ if process found
listProcessId = “#-Pid-Process Name-User “+ vbNewLine
For jix = (ji*perpage)+1 To (ji+1)*perpage
If jix<=i Then
listProcessId = listProcessId+CStr(jix)+”-“+ + CStr(arrayListProcess(jix))+ “-” + CStr(arrayNameProcess(jix))+”-” + CStr(arrayUserProcess(jix)) + vbNewLine
End If
Next
j=0
‘display input box
y= InputBox(“Access #”+CStr(ix+1)+ ” IP (” + CStr(strComputerName) + “)”+ ” of ” +CStr(jC)+” Servers ” + vbNewLine + CStr(i) + ” Process Found, Page “+CStr(ji+1)+” of “+CStr(jpage)+vbNewLine+ vbNewLine+”Choose number for process you want to stop, then click OK. Separated by comma eg 1,4,3 “+ vbNewLine+vbNewLine +listProcessId)
PidArray = Split(Trim(y),”,”)
Dim StrPid
StrPid = “”
For Each pidnumber in PidArray
j=j+1
Redim Preserve ThePid(j)
If Cint(pidnumber) <= i Then
StrPid = StrPid + “-” + CStr(arrayListProcess(pidnumber)) + “-”
End If
Next

‘ check if pid is selected process then terminate
For Each objProcess in objProcessList
Pid = CStr(objProcess.ProcessId)
if(InStr(StrPid,Pid)>0) Then
objProcess.Terminate()
End if
Next
Next
Else
WScript.Echo “No Process Found In Computer “+strComputerName
End If
Else
WScript.Echo “Can’t Connect To : “+strComputerName
End If
ix=ix+1
If Err.Number <> 0 And Err.Description <> “Object required” Then
MsgBox(“Error :” +Err.Description )
Err.Clear
End If

Next
End If
WScript.Echo(“Finished”)

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: