Page 1 of 1 1
Topic Options
#151267 - 2005-11-09 11:35 PM This week's lesson is...
xpanmanx Offline
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. Offline
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
#151269 - 2005-11-09 11:50 PM Re: This week's lesson is...
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
I get the subtype of the array, first as an integer, then as a string. It comes back as a generic object.

I'm not sure what you're driving at...is the array of the wrong type to use a straight UBOUND call against it?

Top
#151270 - 2005-11-10 12:53 AM Re: This week's lesson is...
Chris S. Offline
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
#151271 - 2005-11-10 04:16 AM Re: This week's lesson is...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hmmm.. you dim $x but use $.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151272 - 2005-11-10 07:36 AM Re: This week's lesson is...
NTDOC Administrator Offline
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 Offline
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
#151274 - 2005-11-10 07:11 PM Re: This week's lesson is...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
use the $wmiColl.Count to build your array..

dim $array[$wmiColl.Count]

for each $wmiObj in $wmiColl
$array[$i] = $wmiObj.name
$i = $i + 1
next

Top
#151275 - 2005-11-10 07:35 PM Re: This week's lesson is...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or better yet, count - 1
_________________________
!

download KiXnet

Top
#151276 - 2005-11-10 09:26 PM Re: This week's lesson is...
xpanmanx Offline
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. Offline
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 Offline
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
#151279 - 2005-11-10 11:58 PM Re: This week's lesson is...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
5 stars then. ;-)
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.064 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org