0

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:

  • Is there a stock way in pywin32/underlying WinAPI to look up the aforementioned GUIDs by names? (do not suggest searching the registry by hand)
  • Or maybe some other way to instantiate that object with names?

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.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • Assign the unintelligible GUID to a nicely-named variable, which is basically what a ProgID does for you. – Mark Tolonen Nov 13 '16 at 03:42
  • @MarkTolonen That's an interesting question actually: are ProgIDs guaranteed to be unique like GIUDs? If yes, then how is this facilitated? There is no "practical uniqueness" algorithm behind their "generation", after all. – ivan_pozdeev Nov 13 '16 at 05:15
  • 1
    [A programmatic identifier (ProgID) is a registry entry that can be associated with a CLSID. Like the CLSID, the ProgID identifies a class but with less precision because it is not guaranteed to be globally unique.](https://msdn.microsoft.com/en-us/library/windows/desktop/dd542719(v=vs.85).aspx) – Mark Tolonen Nov 13 '16 at 05:58

1 Answers1

0

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.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152