Solved

getting list of installed programs

Posted on 2001-09-07
3
283 Views
Last Modified: 2010-04-06
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?
0
Comment
Question by:marksmall
3 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6466092
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.
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6466418
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


0
 
LVL 4

Accepted Solution

by:
jeurk earned 100 total points
ID: 6468598
Hi,
Simonet has a nice program that shows this here:
http://www.bhnet.com.br/~simonet/howtoprojs.htm

The file is http://www.bhnet.com.br/~simonet/archive/instapps.zip
With sources of course.

See you.
John.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 111
how can i search if string exist in array ? 3 63
Delphi...Split view - idea? 1 89
CheckListBox usage 3 71
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question