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
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 = "'" & processNameStr & "'"
Set wmiObj = GetObject("WinMgmts:{impersonationLevel=Impersonate}")
Set processObjCol = wmiObj.ExecQuery("SELECT Name FROM Win32_Process Where Name = " & processNameStr)
If processObjCol.Count = 0 Then
isRunningProcess = False
Else
isRunningProcess = True
End If
End function
When I run a script with these functions I end up with an error like this on processObjCol.Count
Line: 115 Char: 2 Error: Invalid query Code: 80041017 Source: SWbemObjectSet
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?