title: simple vbs process query
body: <p>I am new to vbs but have done programming in c, c++ n java. I tried searching over the internet but I still cant find where am i wrong . I am making a script to kill a process named rundll if it exceeds 20% cpu usage.</p>
  
  <pre><code>Option Explicit
  DIM MyPID(5), objProcess, objItems, objitem
  DIM XX, I
  XX = -1
  dim objService
  set objService = getobject("winmgmts:")
  dim Process
  for each Process in objService.InstancesOf("Win32_process")
  if Process.Name = "rundll32.exe" Then XX = XX + 1
  if Process.Name = "rundll32.exe" Then MyPID(XX) = Process.processid
  Next
  
  For I = 0 To 5
  Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
  Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &amp;MyPID(I)&amp; "")
  if (IsNull(objItems)) Then
      Wscript.Echo "No process found"
      Exit For
  End if
  for each objItem in objItems
      if objItems = Null Then
      Wscript.Echo "No process found"
      elseif objItem&gt;20 Then Wscript.Echo "Criminal process found :" &amp; MyPID(I) &amp; " = " &amp; objItem.PercentProcessorTime
      End if
  NEXT
  
  NEXT
  </code></pre>
  
  <p>If the script doesnt find the process it should print no process found ,instead of a complicated null alert that i am getting now</p>
  
  <p>Any help would be appreciated and so wud be suggestions</p>