Search code examples
delphiocx

Detect if an OCX class is registered in Windows


i need to know how can detect if an OCX class (ClassID) is registred in Windows

something like

function IsClassRegistered(ClassID:string):boolean;
begin
//the magic goes here
end;

begin
  if IsClassRegistered('{26313B07-4199-450B-8342-305BCB7C217F}') then
  // do the work
end;

Solution

  • you can check the existence of the CLSID under the HKEY_CLASSES_ROOT in the windows registry.

    check this sample

    function ExistClassID(const ClassID :string): Boolean;
    var
        Reg: TRegistry;
    begin
     try
         Reg := TRegistry.Create;
       try
         Reg.RootKey := HKEY_CLASSES_ROOT;
         Result      := Reg.KeyExists(Format('CLSID\%s',[ClassID]));
       finally
         Reg.Free;
       end;
     except
        Result := False;
     end;
    end;