Detect if OCX class is registered in Windows

I need to know how to determine if an OCX class (ClassID) is registered on 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; 
+6
delphi ocx
source share
3 answers

you can check for CLSID under 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; 
+8
source share

ActiveX / COM is a complex beast, they have many pieces to register with, and Vista + makes it more complicated with the rules of UAC registry virtualization.

The best option is to simply try to create an instance of OCX and see if it succeeds or fails. This will tell you whether OCX is registered correctly, all elements are connected, regardless of whether OCX is used in the context of the calling user, etc.

+2
source share

Problem with (many, many) registry traversal suggestions:

  • There are several registry keys that you will need to look for
  • a class can be registered and does not exist in the registry

Without registration, COM allows you to get a class without registration. Conceptually, you don’t want to know if a class is registered, you just want to know that it is registered enough to create.

Unfortunately, the only (and best) way to do this is to create it:

 //Code released into public domain. No attribution required. function IsClassRegistered(const ClassID: TGUID): Boolean; var unk: IUnknown; hr: HRESULT; begin hr := CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IUnknown, {out}unk); unk := nil; Result := (hr <> REGDB_E_CLASSNOTREG); end; 
+1
source share

All Articles