#192187 - 2009-02-12 04:16 PM
WMI process list returning no element array
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
I have s section of code that I dont know why the array is returning a empty array. This is the code I am running:
Dim $strComputer, $objWMIService, $colProcessList, $objProcess
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colProcessList = $objWMIService.ExecQuery("Select * from Win32_Process)")
If @error
? @Serror
?
EndIf
? UBound($colProcessList)
I am receiving no error, but am getting a -1 ubound. This is running on a XP Pro machine.
Any ideas?
|
|
Top
|
|
|
|
#192191 - 2009-02-12 04:37 PM
Re: WMI process list returning no element array
[Re: Richard H.]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
I added a For Each loop. It still will display nothing. Please forgive ignorance here. I have actually never tapped into the WMI system before.
Dim $strComputer, $objWMIService, $colProcessList, $objProcess
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colProcessList = $objWMIService.ExecQuery("Select * from Win32_Process)")
If @error
? @Serror
?
EndIf
For Each $objProcess in $colProcessList
? $objProcess.Name
Next
My Ultimate goal here is to check for certain processes. If they do not exist, i want to launch the process.
|
|
Top
|
|
|
|
#192192 - 2009-02-12 04:47 PM
Re: WMI process list returning no element array
[Re: coder]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You are not far off.
Be aware that there is a UDF (user defined function) in the UDF forum which will do all the work for you.
This is a test example which works on my XP pro system:
Break ON
$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")
$=SetOption("ASCII","ON")
Global $oWMIService
Dim $oProcess,$colProcess
If Not IsDeclared($Host) Global $Host EndIf
If $Host="" $Host=@WKSTA EndIf
$oWMIService = GetObject("winmgmts:\\"+$Host+"\root\cimv2")
If @ERROR "Cannot access WMI sevrice, error is " @ERROR ": " @SERROR ? Exit @ERROR EndIf
$colProcess=$oWMIService.ExecQuery('Select * from Win32_Process',,48)
If @ERROR "Cannot access WMI sevrice, error is " @ERROR ": " @SERROR ? Exit @ERROR EndIf
For Each $oProcess In $colProcess
"Process: "+$oProcess.Name+@CRLF
Next
Exit 0
|
|
Top
|
|
|
|
#192195 - 2009-02-12 05:14 PM
Re: WMI process list returning no element array
[Re: Richard H.]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
What UDF would that be?
Thanks
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|