#151267 - 2005-11-09 11:35 PM
This week's lesson is...
|
xpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
|
Hi, friends - this week I think I need a lesson in WMI queries. Can someone tell me where I've gone wrong? The array of process names displays beautifully, but $x returns -1, which kinda sucks.
Code:
Dim $wmiColl,$wmiObj,$x $wmiColl=GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Process") For Each $wmiObj in $wmiColl ? $wmiObj.Name Next $x=Ubound($wmiColl) ?$x Get $
|
|
Top
|
|
|
|
#151268 - 2005-11-09 11:40 PM
Re: This week's lesson is...
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Ok, the teacher is in, but I won't tell you the answer. I'll make you work for it.
If you run the following...
Code:
Dim $wmiColl,$wmiObj,$x $wmiColl=GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Process") For Each $wmiObj in $wmiColl ? $wmiObj.Name Next ? VarType($wmiColl) ? VarTypeName($wmiColl)
...you get what? And what does that tell you?
|
|
Top
|
|
|
|
#151270 - 2005-11-10 12:53 AM
Re: This week's lesson is...
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Hmm. Does this explain it yet?
Code:
Dim $wmiColl,$wmiObj,$x $wmiColl=GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Process") For Each $wmiObj in $wmiColl $ = $ + 1 ? "" + $ + ") " + $wmiObj.Name Next ? VarType($wmiColl) ? VarTypeName($wmiColl) ? "Number of items in the WMI collection: " + $wmiColl.Count ? "If UBound returns '-1' does KiXtart see it as an array? " + UBound($wmiColl)
|
|
Top
|
|
|
|
#151272 - 2005-11-10 07:36 AM
Re: This week's lesson is...
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Teacher was in a hurry to step out from work
|
|
Top
|
|
|
|
#151273 - 2005-11-10 06:39 PM
Re: This week's lesson is...
|
xpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
|
That rather sledgehammer with which you're smacking me around the room makes me want to say that $WMICOLL is not an array. So then I'd better build a KiX array based off the contents of $WMICOLL.
This hurts my brain.
Here's my new Code:
Dim $wmiColl,$wmiObj,$t,$v,$w,$x,$y,$z $wmiColl=GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_Process") For Each $wmiObj in $wmiColl $t=$t+1 Next Dim $u[$t] For Each $wmiObj in $wmiColl $u[$x]=$wmiObj.Name $x=$x+1 Next ;======code below this line provides debug output through the console For Each $w in $u ? '$$u[' + $y + ']=' + $w $y=$y + 1 Next ? 'Number of running processes=' + $t $z=Ubound($u) ? 'Number of rows in $u=' + $z Sleep 2
This works fine, although I seem to get an extra blank element at the end of the array...?
So did I jump through the right hoops, or too many hoops?  .
|
|
Top
|
|
|
|
#151276 - 2005-11-10 09:26 PM
Re: This week's lesson is...
|
xpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
|
So, then... Code:
;! Dim $,$v,$w,$x,$y,$z $=GetObject('WinMgmts:root/cimv2').ExecQuery('Select * FROM Win32_Process') Dim $u[$.Count-1] For Each $v in $ $u[$x]=$v.Name $x=$x+1 Next ;!;! ;======code below this line provides debug output through the console For Each $w in $u ? '$$u[' + $y + ']=' + $w $y=$y + 1 Next $z=Ubound($u) ? 'Number of rows in $u=' + $z Sleep 2
KiXgolf score of 147 not counting the debug output.
My goal was to build an 1D array consisting of the names of the process running on the workstation. Thanks for the help, it would seem that I am done.
.
|
|
Top
|
|
|
|
#151277 - 2005-11-10 10:53 PM
Re: This week's lesson is...
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Cool. Did you learn anything?
|
|
Top
|
|
|
|
#151278 - 2005-11-10 11:30 PM
Re: This week's lesson is...
|
xpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
|
I learned that a WMI collection <> a KiXtart array.
I learned that WMI.Count exists.
I confirmed that I have a lot more to learn
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 476 anonymous users online.
|
|
|