Python And COM

John Abel john.abel at
Mon Feb 24 23:17:15 CET 2003


I've searched all over the web, but can't seem to find any documentation on
this.  I am trying to convert the following VBScript code, to Python, with
only minimal success.

Set objCol = GetObject("WinMgmts:").InstancesOf("Win32_LogicalDisk")


import win32com.client

comObj = win32com.client.GetObject( "WinMgmts://." )
for drv in comObj.InstancesOf( "Win32_LogicalDisk" ):
    print drv

Fails with :

Traceback (most recent call last):
  File "D:\Bin\ActiveState\Komodo-2.0\callkomodo\", line 401, in
_do_start, locals, locals)
  File "D:\Bin\ActiveState\Python\lib\", line 349, in run
    exec cmd in globals, locals
  File "D:\MyDevelopment\Python\", line 4, in ?
    for drv in comObj.InstancesOf( "Win32_LogicalDisk" ):
  File "<COMObject WinMgmts:>", line 4, in InstancesOf
line 100, in Dispatch
    return createClass(IDispatch, olerepr, userName,UnicodeToString,
TypeError: 'str' object is not callable

The problem seems to be the InstancesOf call.  Can someone point me in the
right direction for this?  I have Perl code, which basically does the same
(which works OK), so I'm at a loss, as to why the Python way fails.

I'm using ActivePython 2.2.2 build 224, on Win2000 Pro.



More information about the Python-list mailing list