Thanks in advance for any help/suggestions...
I wrote a pretty basic function to check how many times a specific process is running on a machine. It passes the host name to a local variable called strComputerName.
Inside the function is a locally set variable called objWMIService. The first time this line is run it works fine, but any additional times it will error out if i pass a different host to it. I can re-run it many times if I never change what is set to objWMIService.
I included the output after the code...
please note if you try to run the code to reproduce, make sure u replace the ip addresses with ones valid for your network
---
dim strComputer(2)
for x = 1 to 2
strComputer(x)="192.168.0.10" & x
ProcessChecker(strComputer(x))
next
function ProcessChecker(strComputerName)
set objWMIService = nothing
msgbox strComputerName
set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'svchost.exe' ")
wscript.echo "svchost.exe is running " & colProcesses.Count & " times on " & strComputerName & "."
end function
---
The output will look like this for run through 1:
popup 1: 192.168.0.101
(used for tracing the error to make sure the host name gets passed through)
popup 2: 'svchost is running on 192.168.0.101 5 times."
Now the second time:
popup 1: 192.168.0.102
the second hostname still passes through fine...once again this is here for testing
popup 2: Line 16
Char 1
Error 0x8004100A
Code 8004100A
Source Null
----
I wrote a pretty basic function to check how many times a specific process is running on a machine. It passes the host name to a local variable called strComputerName.
Inside the function is a locally set variable called objWMIService. The first time this line is run it works fine, but any additional times it will error out if i pass a different host to it. I can re-run it many times if I never change what is set to objWMIService.
I included the output after the code...
please note if you try to run the code to reproduce, make sure u replace the ip addresses with ones valid for your network
---
dim strComputer(2)
for x = 1 to 2
strComputer(x)="192.168.0.10" & x
ProcessChecker(strComputer(x))
next
function ProcessChecker(strComputerName)
set objWMIService = nothing
msgbox strComputerName
set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'svchost.exe' ")
wscript.echo "svchost.exe is running " & colProcesses.Count & " times on " & strComputerName & "."
end function
---
The output will look like this for run through 1:
popup 1: 192.168.0.101
(used for tracing the error to make sure the host name gets passed through)
popup 2: 'svchost is running on 192.168.0.101 5 times."
Now the second time:
popup 1: 192.168.0.102
the second hostname still passes through fine...once again this is here for testing
popup 2: Line 16
Char 1
Error 0x8004100A
Code 8004100A
Source Null
----