VBS Help, Count same process and report...

October 27, 2011 at 12:47:40
Specs: Windows XP
I run .vbs script per computer to find how many of the same process exists, for import into a DB table. Now we have several computers running the same process and I need a total count across all computers, and can't seem to get it working correctly.

Current capture from individual computer:
strComputer = "v5-ca64" 'Remote Computer
strProcess = "rundbb.exe" 'TNP Process
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process where name like '" & strProcess & "'")
wscript.Echo colProcessList.Count

This script produces a single number for example "4" to represent there are 4 "rundbb.exe" processes found on the computer.

----

My code I am trying to get to work:
arrComputers = Array("v5-ca64","v5-ci64") 'Remote Computers
strProcess = "rundbb.exe" 'TNP Process
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process where name like '" & strProcess & "'")
Next
wscript.Echo colProcessList.Count

I am assuming that the echo is overwriting itself at the end of the script, so you only have a single output more than likely for the last computer in the array scanned. What I need to happen is the number stored and combined at the end to show a total. Example... the output would be "10" and that is the combined number of the "rundbb.exe" processes running across the array of computers.

Help... thanks!


See More: VBS Help, Count same process and report...

Report •

#1
October 28, 2011 at 09:56:54
Just to follow up... this is what I ended up doing for my solution:

arrComputers = Array("P-CA1TNP","P-CA2TNP") 'Remote Computers
strProcess = "rundbb.exe" 'TNP Process
Sum = 0
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process where name like '" & strProcess & "'")
Sum = Sum + colProcessList.Count 'Calculated sum of TNP processes across array
Next
wscript.Echo Sum


Report •
Related Solutions


Ask Question