Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting list of installed programs

Posted on 2001-09-07
3
Medium Priority
?
306 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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