2010. július 19., hétfő

COM/OLE Object Name Utility Procedure


COM/OLE Object Name Utility Procedure


This procedure enables you to browse a list of Registered GUID classes from HKEY_LOCAL_MACHINE\Software\Classes\CLSID. The object name is the name as used by the Delphi function "CreateOleObject('Outlook.Application')" etc. The procedure sets a TStrings object (eg. TListBox.Items or TMemo.Lines) to the Description of the GUID (if any), the Separator (Default is "@") and the OLE object name (eg. Outlook.Application.9).

There are numerous objects in this portion of the registry, I was only interested in entries that had a "ProgID" key within. Another key of interest is "VersionIndependantProgID" which exists for certain entries. eg. Microsft Outlook has for instance ..

ProgID = Outlook.Application.9
VersionIndependantProgID = Outlook.Application

You may wish to return the version independant key instead of the actual key (up to you).

An example of use could be ....

ListBox1.Sorted := true;

The output looks something like
Microsoft OLE DB Service Component Data Links@DataLinks
Microsoft Organization Extension@MSExtOrganization
Microsoft OrganizationUnit Extension@MSExtOrganizationUnit
Microsoft Outlook@Outlook.Application.9
Microsoft Photo Editor 3.0 Photo@MSPhotoEd.3
Microsoft Photo Editor 3.0 Scan@MSPhotoEdScan.3
Microsoft Powerpoint Application@PowerPoint.Application.9
Microsoft PowerPoint Presentation@PowerPoint.Show.8
Microsoft PowerPoint Slide@PowerPoint.Slide.8
Microsoft PptNsRex Control@PptNsRex.PptNsRex.1
Microsoft PrintQueue Extension@MSExtPrintQueue
Microsoft Repository Class Definition@ReposClassDef.0

The listing contains many interesting and unexplored possibilities.
Happy Hunting.

uses Registry;

procedure LoadCLSID(StringList: TStrings; Separator: char = '@');
  REGKEY = 'Software\Classes\CLSID';
  WinReg: TRegistry;
  KeyNames, SubKeyNames: TStringList;
  i: integer;
  KeyDesc: string;
  KeyNames := TStringList.Create;
  SubKeyNames := TStringList.Create;
  WinReg := TRegistry.Create;

  if WinReg.OpenKey(REGKEY, false) then

    // Traverse list of GUID numbers eg. {00000106-0000-0010-8000-00AA006D2EA4}
    for i := 1 to KeyNames.Count - 1 do
      // Check if key "ProgID" exists in open key ?
      if WinReg.OpenKey(REGKEY + '\' + KeyNames[i], false) then
        if WinReg.KeyExists('ProgID') then
          KeyDesc := WinReg.ReadString(''); // Read (Default) value

          if WinReg.OpenKey(REGKEY + '\' + KeyNames[i] +
            '\ProgID', false) then
            // Add description of GUID and OLE object name to passed list
            StringList.Add(KeyDesc + Separator + WinReg.ReadString(''));


Nincsenek megjegyzések:

Megjegyzés küldése