Python And COM

John Abel john.abel at pa.press.net
Mon Feb 24 17:17:15 EST 2003


Hi,

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")

To:

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\kdb.py", line 401, in
_do_start
    self.kdb.run(code_ob, locals, locals)
  File "D:\Bin\ActiveState\Python\lib\bdb.py", line 349, in run
    exec cmd in globals, locals
  File "D:\MyDevelopment\Python\Win32Test.py", line 4, in ?
    for drv in comObj.InstancesOf( "Win32_LogicalDisk" ):
  File "<COMObject WinMgmts:>", line 4, in InstancesOf
  File
"D:\Bin\ActiveState\Python\Lib\site-packages\win32com\client\dynamic.py",
line 100, in Dispatch
    return createClass(IDispatch, olerepr, userName,UnicodeToString,
lazydata)
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.

Thanks

John






More information about the Python-list mailing list