Please help me enumerate COM and avoid VB

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Please help me enumerate COM and avoid VB

John H Woods
Hi All,

I have a VB script that iterates over the drives in a computer and returns the % used on each drive  (the script is attached below).  I can invoke the script using WinProcess cshOne: but I'd like to do it directly in COM.  However, I have hit an obstacle.  Can anyone please help me?

| wmiService driveSet numberOfDrives enumerator |
"ISWbemServicesEx" wmiService := AdvancedDispatchDriver pathName: 'winmgmts:'.
"ISWbemObjectSet" driveSet := wmiService
   invokeMethod: 'ExecQuery'
   with: 'Select * from Win32_LogicalDisk Where DriveType = 3'. "i.e. get all Hard Drives"

numberOfDrives := driveSet getProperty: #Count. "This correctly produces 3 on my machine (C: D: H:)"

enumerator := (driveSet getProperty: #_NewEnum) queryInterface: IID_IEnumVARIANT

This gives an Error: 'Unsupported Enumeration Interface.'  But if you use IID_IEnum (for instance) you get nil, the normal result for an interface that isn't supported by the COM object.   How can I iterate over the 3 drives in this collection?

Very many thanks in advance ...

. . . John H Woods

VB makes it look easy.  Hell it is easy, I just can't code the For Each - Next into Smalltalk.  Please help!

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
    intFreeSpace = objDisk.FreeSpace
    intTotalSpace = objDisk.Size
    pctFreeSpace = intFreeSpace / intTotalSpace
    Wscript.Echo objDisk.DeviceID, FormatPercent(pctFreeSpace)
Next
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Please help me enumerate COM and avoid VB

Boris Popov, DeepCove Labs (SNN)
John,

If you're interested in that specific query, load up Windows Goodies
parcel and execute the following,

PCFilename volumesAndSpaces

Dictionary (
'C:\'->#(27005931520 79949717504 27005931520)
'D:\'->#(60655132672 81956655104 60655132672)
)

Hope this helps,

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
Behalf
> Of John H Woods
> Sent: Tuesday, July 08, 2008 2:30 AM
> To: [hidden email]
> Subject: [vwnc] Please help me enumerate COM and avoid VB
>
>
> Hi All,
>
> I have a VB script that iterates over the drives in a computer and
returns
> the % used on each drive  (the script is attached below).  I can
invoke

> the
> script using WinProcess cshOne: but I'd like to do it directly in COM.
> However, I have hit an obstacle.  Can anyone please help me?
>
> | wmiService driveSet numberOfDrives enumerator |
> "ISWbemServicesEx" wmiService := AdvancedDispatchDriver pathName:
> 'winmgmts:'.
> "ISWbemObjectSet" driveSet := wmiService
>    invokeMethod: 'ExecQuery'
>    with: 'Select * from Win32_LogicalDisk Where DriveType = 3'. "i.e.
get
> all Hard Drives"
>
> numberOfDrives := driveSet getProperty: #Count. "This correctly
produces 3
> on my machine (C: D: H:)"
>
> enumerator := (driveSet getProperty: #_NewEnum) queryInterface:
> IID_IEnumVARIANT
>
> This gives an Error: 'Unsupported Enumeration Interface.'  But if you
use
> IID_IEnum (for instance) you get nil, the normal result for an
interface
> that isn't supported by the COM object.   How can I iterate over the 3
> drives in this collection?
>
> Very many thanks in advance ...
>
> . . . John H Woods
>
> VB makes it look easy.  Hell it is easy, I just can't code the For
Each -
> Next into Smalltalk.  Please help!
>
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")

> Set colDisks = objWMIService.ExecQuery _
>     ("Select * from Win32_LogicalDisk Where DriveType = 3")
> For Each objDisk in colDisks
>     intFreeSpace = objDisk.FreeSpace
>     intTotalSpace = objDisk.Size
>     pctFreeSpace = intFreeSpace / intTotalSpace
>     Wscript.Echo objDisk.DeviceID, FormatPercent(pctFreeSpace)
> Next
>
> --
> View this message in context: http://www.nabble.com/Please-help-me-
> enumerate-COM-and-avoid-VB-tp18335280p18335280.html
> Sent from the VisualWorks mailing list archive at Nabble.com.
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Please help me enumerate COM and avoid VB

John H Woods
Hi Boris, that is very useful info (and was a very quick response, thanks).  However, I'd really like to be able to iterate over COM obects anyway because I'm interested in other aspects of the WMI (Windows Management Instrumentation) such as process and processor statistics.

John

Boris Popov-2 wrote
John,

If you're interested in that specific query, load up Windows Goodies
parcel and execute the following,

PCFilename volumesAndSpaces

Dictionary (
'C:\'->#(27005931520 79949717504 27005931520)
'D:\'->#(60655132672 81956655104 60655132672)
)