Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Registry to check if an application is installed 1

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
My application needs to check if another application is installed or not. As the application folder could have various names, e.g. Delphi6, Delphi 7, etc, it would be better to search the registry.

TRegistry doesn't appear to have any search properties. Does anyone have a method to search the registry for a key? Something like if x then y. Using wildcards would be a bonus, but not a necessity.

Thanks.
 
Applications traditionally place a key in

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

To list which applications have listed themselves there, create a new project, drop a TMemo and a TButton on the form, doubleclick the TButton's OnClick event, and add the following to your unit:
Code:
implementation
uses Registry;

{$R *.dfm}

procedure Form1.Button1Click( Sender: TObject );
  var
    names: TStringList;
    index: integer;
    appid: string;
  begin
  with TRegistry.Create do
    try
      RootKey := HKEY_LOCAL_MACHINE;
      Access  := KEY_READ;
      if not OpenKey( 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', False )
        then exit;
      names := TStringList.Create;
      try
        GetKeyNames( names );
        for index := 0 to names.Count -1 do
          if OpenKey( names[ index ], false )
            then try
                 appid := ReadString( 'DisplayName' );
                 if appid <> ''
                   then begin
                        Memo1.Lines.Add( 'Key Name: ' +names[ index ] )
                        Memo1.Lines.Add( 'Application Name: ' +appid )
                        end
                 except
                 end
      finally
        names.Free
      end
    finally
      free
    end
  end;
The DisplayName is how the application represents itself in the Add/Remove Programs applet of the Control Panel. So you'll want to string match AnsiPos or something else more sophisticated than '='.

Hope this helps.
 
Oh yeah, obviously this requires access rights to HKLM.
If you don't have that, you might want to search through the Program Files folder, or the Programs start menu folder.
Heh...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top