Hi,

Using VFP 9.0 sp1. I'm working with a collection of information retrieved
from the win32_computersystem class. It returns a collection and I'm
wondering what is the best way to get this into a table form? The only
method I see is using a FOR... EACH process. I'm just wondering if there is
a more elegent method.

Also, is there a way to process an object from a collection and list all of
it's properties, assuming you don't know the names of those properties?

Lastly, is there a way to see some of these classes like
win32_computersystem class and win32_operatingsystem classes using the
object browser? I think these are part of the .Net 3.0 framework.

Thanks in advance,
Linn

Re: Converting a collection to a table? by Bernhard

Bernhard
Fri Jun 29 08:48:06 CDT 2007

Hi Linn,

> Also, is there a way to process an object from a collection and list all of
> it's properties, assuming you don't know the names of those properties?
Have a look at aMembers()

Regards
Bernhard Sander

Re: Converting a collection to a table? by Roger

Roger
Fri Jun 29 09:27:20 CDT 2007


"Linn Kubler" <lkubler@chartwellwisc2.com> wrote:

> Hi,
>
> Using VFP 9.0 sp1. I'm working with a collection of information
> retrieved from the win32_computersystem class. It returns a
> collection and I'm wondering what is the best way to get this into a
> table form? The only method I see is using a FOR... EACH process.
> I'm just wondering if there is a more elegent method.

Since you need to iterate through all members of the collection,
I don't see what's inelegant about using For Each.

> Also, is there a way to process an object from a collection and list
> all of it's properties, assuming you don't know the names of those
> properties?

As Bernhard suggested, you can use AMembers, but for a COM object
you need to pass 3 as the 3rd parameter ... eg
lnMembers = AMembers(<arrayname>,<object>,3)
However, according to VFP9 help, a value of 3 is not supported
in .app or .exe applications. I haven't tested this.

> Lastly, is there a way to see some of these classes like
> win32_computersystem class and win32_operatingsystem classes using
> the object browser?

Not that I'm aware of.

>I think these are part of the .Net 3.0 framework.

I thought we were talking about WMI?

-Roger




Re: Converting a collection to a table? by Linn

Linn
Fri Jun 29 09:51:28 CDT 2007


"Bernhard Sander" <fuchs@no.spam> wrote in message
news:uHeZjQluHHA.4916@TK2MSFTNGP04.phx.gbl...
> Hi Linn,
>
>> Also, is there a way to process an object from a collection and list all
>> of it's properties, assuming you don't know the names of those
>> properties?
> Have a look at aMembers()
>
> Regards
> Bernhard Sander

Hi Bernhard,

Thanks for the suggestion but I can't get it to work. Here's my code:
colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
retno=AMEMBERS(gaComputerProps, colSettings, 1)
?retno
?alen(gaComputerProps)
DISPLAY MEMORY LIKE gaComputerProps

retno returns zero and I get an error on alen() saying variable
gaComputerProps is not found and nothing gets displayed for the last line.

If I do this:
colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
MESSAGEBOX("Name: " + NVL(objComputer.Name, 'NULL'))
Next

It works so I'm not sure what's wrong.

Thanks,
Linn



Re: Converting a collection to a table? by Bernhard

Bernhard
Fri Jun 29 10:20:10 CDT 2007

Hi Linn,

> If I do this:
> colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
> For Each objComputer in colSettings
> MESSAGEBOX("Name: " + NVL(objComputer.Name, 'NULL'))
> Next
>
> It works so I'm not sure what's wrong.
This looks, as if colSettings is an array or a collection.
Then iterate over colSettings and use aMember on each objComputer:

colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
aMember(gaMember, objComputer)
Next

Maybe you have to add some more of the parameters of aMember.

Btw, what do you see in the debugger if you look at colSettings in the watch
window or locals window?

Regards
Bernhard Sander


Re: Converting a collection to a table? by Olaf

Olaf
Fri Jun 29 10:49:29 CDT 2007

Hi Linn,

those WMI collections are very different. Even intellisense makes
problems showing you properties.

a for each loop seems to be the only way to go.

> If I do this:
> colSettings = objWMIService.ExecQuery ("SELECT * FROM
> Win32_ComputerSystem")
> For Each objComputer in colSettings
> MESSAGEBOX("Name: " + NVL(objComputer.Name, 'NULL'))
> Next

To find other properties besides the computer name:

objWMIService=GetObject([winmgmts:])
colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
For Each objProperty in objComputer.Properties_
If objProperty.name $ "OEMStringArray, Roles"
Loop
EndIf
? objProperty.name+":"
? evaluate("objComputer."+objProperty.name)
EndFor
Exit && to start with just one computer
EndFor

OEMStringArray and Roles seem to be further collections, eval errors on
them.

The properties seem to be there only, after they are touched for the first
time.

When you do...

Create Cursor curSettings (Name C(50), UserName C(50))
objWMIService=GetObject([winmgmts:])
colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
Insert Into curSettings from Name objComputer
EndFor

...empty records are added to curSettings.
If you just evaluate the properties...

Create Cursor curSettings (Name C(50), UserName C(50))
objWMIService=GetObject([winmgmts:])
colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")
For Each objComputer in colSettings
For Each objProperty in objComputer.Properties_
If objProperty.name $ "OEMStringArray, Roles"
Loop
EndIf
=Evaluate("objComputer."+objProperty.name)
EndFor
Insert Into curSettings from Name objComputer
EndFor

...it works.

Now all you need to do is define all the properties you want stored in a
cursor
as the cursors fields.

Bye, Olaf.