def GetGeneratedInfos(): zip_pos = win32.com.__gen_path__.find(".zip\\") if zip_pos >= 0: import zipfile zip_file = win32.com.__gen_path__[:zip_pos + 4] zip_path = win32.com.__gen_path__[zip_pos + 5:].replace("\\", "/") zf = zipfile.ZipFile(zip_file) infos = {} for n in zf.namelist(): if not n.startswith(zip_path): continue base = n[len(zip_path) + 1:].split("/")[0] try: iid, lcid, major, minor = base.split("x") lcid = int(lcid) major = int(major) minor = int(minor) iid = win32types.IID("{" + iid + "}") except ValueError: continue except win32types.com_error: # invalid IID continue infos[(iid, lcid, major, minor)] = 1 zf.close() return list(infos.keys()) else: # on the file system files = glob.glob(win32.com.__gen_path__ + "\\*") ret = [] for file in files: if not os.path.isdir(file) and not os.path.splitext( file)[1] == ".py": continue name = os.path.splitext(os.path.split(file)[1])[0] try: iid, lcid, major, minor = name.split("x") iid = win32types.IID("{" + iid + "}") lcid = int(lcid) major = int(major) minor = int(minor) except ValueError: continue except win32types.com_error: # invalid IID continue ret.append((iid, lcid, major, minor)) return ret
def GetActiveObject(Class, clsctx=pythoncom.CLSCTX_ALL): """ Python friendly version of GetObject's ProgID/CLSID functionality. """ resultCLSID = pywintypes.IID(Class) dispatch = pythoncom.GetActiveObject(resultCLSID) dispatch = dispatch.QueryInterface(pythoncom.IID_IDispatch) return __WrapDispatch( dispatch, Class, resultCLSID=resultCLSID, clsctx=clsctx)
def getevents(clsid): """Determine the default outgoing interface for a class, given either a clsid or progid. It returns a class - you can conveniently derive your own handler from this class and implement the appropriate methods. This method relies on the classes produced by makepy. You must use either makepy or the gencache module to ensure that the appropriate support classes have been generated for the com server that you will be handling events from. Beware of COM circular references. When the Events class is connected to the COM object, the COM object itself keeps a reference to the Python events class. Thus, neither the Events instance or the COM object will ever die by themselves. The 'close' method on the events instance must be called to break this chain and allow standard Python collection rules to manage object lifetimes. Note that DispatchWithEvents() does work around this problem by the use of a proxy object, but if you use the getevents() function yourself, you must make your own arrangements to manage this circular reference issue. Beware of creating Python circular references: this will happen if your handler has a reference to an object that has a reference back to the event source. Call the 'close' method to break the chain. Example: >>>win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0,1,1) <module 'win32com.gen_py..... >>> >>> class InternetExplorerEvents(win32com.client.getevents("InternetExplorer.Application.1")): ... def OnVisible(self, Visible): ... print "Visibility changed: ", Visible ... >>> >>> ie=win32com.client.Dispatch("InternetExplorer.Application.1") >>> events=InternetExplorerEvents(ie) >>> ie.Visible=1 Visibility changed: 1 >>> """ # find clsid given progid or clsid clsid = str(pywintypes.IID(clsid)) # return default outgoing interface for that class klass = gencache.GetClassForCLSID(clsid) try: return klass.default_source except AttributeError: # See if we have a coclass for the interfaces. try: return gencache.GetClassForCLSID( klass.coclass_clsid).default_source except AttributeError: return None
def GetClassForProgID(progid): """Get a Python class for a Program ID Given a Program ID, return a Python class which wraps the COM object Returns the Python class, or None if no module is available. Params progid -- A COM ProgramID or IID (eg, "Word.Application") """ clsid = win32types.IID(progid) # This auto-converts named to IDs. return GetClassForCLSID(clsid)
def GetModuleForProgID(progid): """Get a Python module for a Program ID Given a Program ID, return a Python module which contains the class which wraps the COM object. Returns the Python module, or None if no module is available. Params progid -- A COM ProgramID or IID (eg, "Word.Application") """ try: iid = win32types.IID(progid) except win32types.com_error: return None return GetModuleForCLSID(iid)
FILE_PREFETCH_TYPE_MAX = 4 FILESYSTEM_STATISTICS_TYPE_NTFS = 1 FILESYSTEM_STATISTICS_TYPE_FAT = 2 FILE_SET_ENCRYPTION = 0x00000001 FILE_CLEAR_ENCRYPTION = 0x00000002 STREAM_SET_ENCRYPTION = 0x00000003 STREAM_CLEAR_ENCRYPTION = 0x00000004 MAXIMUM_ENCRYPTION_VALUE = 0x00000004 ENCRYPTION_FORMAT_DEFAULT = 0x01 COMPRESSION_FORMAT_SPARSE = 0x4000 COPYFILE_SIS_LINK = 0x0001 COPYFILE_SIS_REPLACE = 0x0002 COPYFILE_SIS_FLAGS = 0x0003 WMI_DISK_GEOMETRY_GUID = pywintypes.IID( "{25007F51-57C2-11D1-A528-00A0C9062910}") GUID_DEVINTERFACE_CDROM = pywintypes.IID( "{53F56308-B6BF-11D0-94F2-00A0C91EFB8B}") GUID_DEVINTERFACE_FLOPPY = pywintypes.IID( "{53F56311-B6BF-11D0-94F2-00A0C91EFB8B}") GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR = pywintypes.IID( "{4D36E978-E325-11CE-BFC1-08002BE10318}") GUID_DEVINTERFACE_COMPORT = pywintypes.IID( "{86E0D1E0-8089-11D0-9CE4-08003E301F73}") GUID_DEVINTERFACE_DISK = pywintypes.IID( "{53F56307-B6BF-11D0-94F2-00A0C91EFB8B}") GUID_DEVINTERFACE_STORAGEPORT = pywintypes.IID( "{2ACCFE60-C130-11D2-B082-00A0C91EFB8B}") GUID_DEVINTERFACE_CDCHANGER = pywintypes.IID( "{53F56312-B6BF-11D0-94F2-00A0C91EFB8B}") GUID_DEVINTERFACE_PARTITION = pywintypes.IID(