I've been using win32com.client to work with IE via COM, but recently had a need to start using comtypes.client because it provides a better wrapper for IE. <br>However, when I want to grab an existing IE using comtypes.client.GetActiveObject() the result is always the same as illustrated below<br>
<br><font size="1"><span style="font-family: courier new,monospace;">H:\devel\workspace\web\src>python</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">win32</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Type "help", "copyright", "credits" or "license" for more information.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>>> import comtypes.client</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> ie = comtypes.client.CreateObject('InternetExplorer.Application')</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>>> ie.visible = True</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> ie.__clsid</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">'{0002DF01-0000-0000-C000-000000000046}'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> ie._iid_</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">GUID("{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> newie = comtypes.client.GetActiveObject('InternetExplorer.Application')</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Traceback (most recent call last):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> File "<stdin>", line 1, in <module></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> File "c:\python25\lib\site-packages\comtypes\client\__init__.py", line 164, in</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> GetActiveObject</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> obj = comtypes.GetActiveObject(clsid, interface=interface)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> File "C:\Python25\Lib\site-packages\comtypes\__init__.py", line 990, in GetAct</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">iveObject</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> File "\loewis\25\python\Modules\_ctypes\callproc.c", line 757, in GetResult</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">WindowsError: [Error -2147221021] Operation unavailable</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>>> newie = comtypes.client.GetActiveObject(ie.__clsid)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Traceback (most recent call last):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> File "<stdin>", line 1, in <module></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> File "c:\python25\lib\site-packages\comtypes\client\__init__.py", line 164, in</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GetActiveObject</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> obj = comtypes.GetActiveObject(clsid, interface=interface)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> File "C:\Python25\Lib\site-packages\comtypes\__init__.py", line 990, in GetAct</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">iveObject</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> File "\loewis\25\python\Modules\_ctypes\callproc.c", line 757, in GetResult</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">WindowsError: [Error -2147221021] Operation unavailable</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>></span></font><br>
<br>Has anyone got any bright ideas on how to get this working properly? I really appreciate any help.<br>