Solved

getting list of installed programs

Posted on 2001-09-07
3
284 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 167
Controlled Assessment GCSE - desperate help needed 4 110
JAudiorecorder record freezing the app 29 82
Firemonkey BASS_Init into a thread 17 50
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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