[python-win32] Dispatch InternetExplorer.Application fails

Tim Golden mail at timgolden.me.uk
Tue May 27 21:46:10 CEST 2008


Rickey, Kyle W wrote:
> Whenever I try the following:
> 
>>> import win32com.client
>>> ie = win32com.client.Dispatch("InternetExplorer.Application")
> 
> I get this traceback:
> 
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
>   File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line
> 95, in Dispatch
>     dispatch, userName =
> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line
> 98, in _GetGoodDispatchAndUserName
>     return (_GetGoodDispatch(IDispatch, clsctx), userName)
>   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line
> 78, in _GetGoodDispatch
>     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> com_error: (-2147024894, 'The system cannot find the file specified.',
> None, None)
> 
> Any ideas what would cause this? My end goal is to COM into IE and load
> an xml file, then print it to PDF.

FWIW, you might find it worth looking at PAMIE which uses COM
the way you're doing, but which has already ironed out a few
creases. That said, it doesn't really answer your question. Can
you see what result this script gives:

<code>
import os
import _winreg

hKey = _winreg.OpenKey (
   _winreg.HKEY_CLASSES_ROOT,
   r"InternetExplorer.Application\CLSID"
)
clsid, type = _winreg.QueryValueEx (hKey, "")

print clsid

hKey = _winreg.OpenKey (
   _winreg.HKEY_CLASSES_ROOT,
   r"CLSID\%s\LocalServer32" % clsid
)
server, type = _winreg.QueryValueEx (hKey, "")

print server, os.path.exists (server.strip ('"'))

<code>

This should, crudely, go through the same steps that
the Dispatch process does and should show up whether
IE's not where it thinks it should be. The strip ()
on the server name is because, on my machine, the
location is double-quoted, presumably because it's
got an embedded space which would cause some problem
in the mechanism.

TJG


More information about the python-win32 mailing list