Link to home
Start Free TrialLog in
Avatar of marksmall
marksmall

asked on

getting list of installed programs

how can i get a list of installed programs intoa listbox and then have the ability to delete/unistall them through my delphi application!

is that possible?
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

It's in the registry

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Loop through all the keys in there, and the description for each key is in a StringValue called DisplayName

To remove it, just delete the subkey.
To uninstall it, read the StringValue called UninstallString, and just execute the command.

NOTE: Those without a DisplayName should be ignored.



DragonSlayer.
Avatar of bugroger
bugroger

Hi,

try this function:

// If the function succeeds, the return value is the number of installed programs
// otherwise the return value is -1
Function GetInstalledPrograms(PRGListBox : TListBox) : Integer;
VAR
 rs            : string;

 OpenKey       : HKEY;

 KeyIndex,
 KeyNameLength,
 RetValue      : Cardinal;
 KeyNameBuf    : array of char;

 Function GetDisplayName(KeyName : String) : string;
 VAR
  PRGKey    : HKEY;
  NameBuf   : array[0..255] of char;
  ValueType,
  ValueSize : Cardinal;
  err       : Cardinal;
 Begin
  Result := '';
  IF REGOpenKey(HKEY_LOCAL_MACHINE,
                PCHAR('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'+'\' + KeyName),
                PRGKey)
     <> ERROR_SUCCESS then Result := '*' else
  Begin
   ValueSize := Length(NameBuf);
   IF REGQueryValueEx(PRGKey, PCHAR('Displayname'), NIL, @ValueType, @NameBuf, @ValueSize)
      <> ERROR_SUCCESS then
   Begin
    ValueSize := Length(NameBuf);
    IF REGQueryValueEx(PRGKey, PCHAR('QuietDisplayname'), NIL, @ValueType, @NameBuf, @ValueSize)
       <> ERROR_SUCCESS then Result := KeyName;
   End;
   IF Result = '' then Result := STRING(NameBuf);
   REGCloseKey(PRGKey);
  End;
 End;


Begin
 Result := 0;
 SetLength(KeyNameBuf, 256);
 // Open Key
 IF REGOpenKey(HKEY_LOCAL_MACHINE,
               PCHAR('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'),
               OpenKey)
    <> ERROR_SUCCESS then Result := -1 else
 Begin
  KeyIndex := 0;
  Repeat
   KeyNameLength := Length(KeyNameBuf);
   RetValue      := RegEnumKeyEx(OpenKey, KeyIndex, PCHAR(KeyNameBuf),
                                 KeyNameLength, NIL, NIL, NIL, NIL);

   IF RetValue = ERROR_SUCCESS then
   Begin
    rs := GetDisplayName(PCHAR(KeyNameBuf));
    IF rs <> '*' then
    Begin
        //add the PRG Name to the listbox
            PRGListBox.Items.Add(rs);
     Inc(Result);
    End else Result := -1;
   End;
   Inc(KeyIndex);
   Application.ProcessMessages;
  Until (RetValue <> ERROR_SUCCESS)or(Result = -1);
  RegCloseKey(OpenKey);
 End;
 SetLength(KeyNameBuf, 0);
End;


ex. call:

procedure TForm1.Button1Click(Sender: TObject);
begin
 IF GetInstalledPrograms(ListBox1) = -1 then ShowMessage('ERROR');
end;

GL
 Bug


ASKER CERTIFIED SOLUTION
Avatar of jeurk
jeurk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial