Search code examples
delphioledbado

How to check if an OLEDB driver is installed on the system?


How can I make sure that a certain OLEDB driver is installed when I start my application? I use ADO from Delphi and would like to display a descriptive error message if the driver is missing. The error that's returned from ADO isn't always that user-friendly.

There are probably a nice little function that returns all installed drivers but I haven't found it.


Solution

  • Each provider has a GUID associated with its class. To find the guid, open regedit and search the registry for the provider name. For example, search for "Microsoft Jet 4.0 OLE DB Provider". When you find it, copy the key (the GUID value) and use that in a registry search in your application.

    function OleDBExists : boolean;
    var
      reg : TRegistry;
    begin
      Result := false;
    
      // See if Advantage OLE DB Provider is on this PC
      reg := TRegistry.Create;
      try
        reg.RootKey := HKEY_LOCAL_MACHINE;
        Result := reg.OpenKeyReadOnly( '\SOFTWARE\Classes\CLSID\{C1637B2F-CA37-11D2-AE5C-00609791DC73}' );
      finally
        reg.Free;
      end;
    end;