title: Invalid query on SWbemObjectSet in WSH VBScript
body: <p>I have a problem I am hoping someone can help me with. I am running a VBScript in WScript where these 2 functions work together to see when a process has closed</p>
  
  <pre><code>function closeApp(appNameStr)
      '* What ever code required to close the application here *
      Do Until isRunningProcess(appNameStr) = False
          Wscript.Sleep 250
      Loop
  end function
  
  function isRunningProcess(processNameStr)
      Dim wmiObj, processObjCol
      processNameStr = "'" &amp; processNameStr &amp; "'"
  
      Set wmiObj = GetObject("WinMgmts:{impersonationLevel=Impersonate}")
      Set processObjCol = wmiObj.ExecQuery("SELECT Name FROM Win32_Process Where Name = " &amp; processNameStr)
  
      If processObjCol.Count = 0 Then
          isRunningProcess = False
      Else
          isRunningProcess = True
      End If
  End function
  </code></pre>
  
  <p>When I run a script with these functions I end up with an error like this on processObjCol.Count</p>
  
  <p>Line: 115
  Char: 2
  Error: Invalid query
  Code: 80041017
  Source: SWbemObjectSet</p>
  
  <p>After sending almost everything I could think to a log file, I found that it was running through the Do Until Loop fine the first time but after that is when this error would show up. I've tried setting wmiObj and processObjCol to Nothing at the end of isRunningProcess with no changes to the error. Any thoughts? Do I need to terminate the WMI Service some how?</p>