Solved

getting list of installed programs

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now