These are the basic steps I'm using in AdminScriptEditor to provide COM "ScriptComplete", which of course requires getting the typelib from a known progid:

  • Call CLSIDFromProgID to get the CLSID corresponding to the Prog ID
  • Read HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\Typelib key
  • If the above value exists, read its default value. This value will be the GUID representing the typelibrary.
  • Once you get the GUID representing the typelibrary, read the default value of HKEY_CLASSES_ROOT\Typelib\<GUID representing the
    typelibrary>\<Version>\<Sub Version>\win32
  • This default value will be the full path to the typelibrary
  • If you do not find the Typelib key under HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component> in Step 2, read the default value of one of the following:
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\InprocServer (for 16 bit DLLs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\InprocServer32 (for 32 bit DLLs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\LocalServer (for 16 bit EXEs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\LocalServer32 (for 32 bit EXEs)


Like Shawn points out, though, this procedure doesn't work in every case. The immediate exceptions that come to mind are the office exe's and several of the VBScript-specific ProgIDs. This should cover the vast majority, though.

I actually contacted MS COM development team on this and they told me there's no way to guarantee the result with this method. If you're asking specifically about how to absolutely account for these exception types, to my knowledge the only way to do it is a less-than-ideal hack. In your example, however, IIRC, the result is the same path and filename except the extension is .exe. So, if the resulting file is an .exe you can check the same directory for an .olb file with the same name and if you find it query the typelib from there. Again, certainly not an ideal solution, but will get you close. IIRC, some of the Office exe and olb files were not even in the same directory, but I can't remember which apps and Office versions those were--so in those cases there's no resolution.

If you find something that is a bit more concrete I would love to know about it.

HTH


Edited by Stevie (2004-09-16 05:38 AM)
_________________________
Stevie