pythonpywin32pythoncom

Instantiate COM object that doesn't have ProgID by class/interface name


pywin32 docs for client-side COM show this basic way to instantiate COM objects:

obj = win32com.client.Dispatch("<ProgID>")

I'm trying to work with PersistentZoneIdentifier akin to Manipulating the zone identifier to specify where a file was download from – The Old New Thing - MSDN blogs. That class, as the registry at HKEY_CLASSES_ROOT\CLSID\{0968e258-16c7-4dba-aa86-462dd61e31a3} shows, doesn't have a corresponding ProgID.

I see that there's an underlying pythoncom.CoCreateInstance function that accepts a CLSID to instantiate and an IID to apparently query from it.

But this is inconvenient because I have to use unintelligible GUIDs instead of human-readable names.


The question is:


What I tried and failed: win32com.client.IDispatch(<class/interface name>), pythoncom.IID(<class/interface name>). Also looked through the Net, MSDN and PyWin32 docs, of course.


Solution

  • There is no, and can't be any, "stock mechanism" to instantiate a class/query an interface by its name because their names aren't guaranteed to be unique, unlike GUIDs.