Thursday 21 July 2011

VB Script to kill the process using Wait Method and Do While Loop

Option Explicit
Dim objWMIService,objProcess, objProcess1, colProcess, strProcess,strProcess1
Dim xComputer,Flag
strProcess = "'notepad.exe'"
strProcess1 = "'cmd.exe'"
xComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& xComputer & "\root\cimv2")
 
Do
   Flag = 0
   WScript.Sleep 60000
   Set colProcess = objWMIService.ExecQuery _
   ("Select * from Win32_Process Where Name = " & strProcess)
   For Each objProcess in colProcess
   If objProcess.Name = strProcess then   
   objProcess.Terminate()
   Flag=1
   End If
   Next 
 
Loop Until Flag = 1

1 comment: