Pegar softwares

Delphi

15/08/2003

E ai .. blz ..
bom gostaria de saber se tem como conseguir pegar todos os softwares instalados no micro ..(q nem aparece no painel de controle) e colocar em uma memo ou algo do genero.
E tb se tem como pegar o hardware instalado ...

Valew e ate mais ...


Robson cruz junior


Robsonjunior

Robsonjunior

Curtidas 0

Respostas

Cebikyn

Cebikyn

15/08/2003

Como pegar os softwares instalados:

unit Unit1;

(*

   How to retrieve a list of installed applications

   by Alex Simonetti Abreu
      simonet@bhnet.com.br


   This How-To Project shows you how to retrieve a list of
   all installed applications on a Windows 9x/NT/2k machine.

   The retrieved list of applications is similar to that
   available in the Control Panel in the "Add/Remove Programs"
   applet.

   All information is read from the Registry, from the key
   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
   There is a list of subkeys inside that key, and each key
   corresponds to one installed application/driver/etc. Please
   note that not all the keys in that entry are concerning
   installed APPLICATIONS. Many of them are for drivers,
   add-ons, etc, and are not displayed in the Control Panel
   applet.

   Also note that not all installed applications have an entry
   under the forementioned key. A given application will only
   have a correspondent subkey if its installer application
   created an uninstall key.

   The actual name of the subkey for each application doesn´t
   often say much about the name of the application. The real name
   of the application must be read from the value DisplayName
   under each key. This is why there´s a loop with all the keys
   retrieved and lots of tests.

   As a bonus, the program also features 2 other tips:
   - How to exclude the selected Uninstall information from the
     Registry. This is specially useful when you have manually
     removed the application from the computer but its
     uninstall information remains there;

   - How to invoke a program´s uninstal application (like UnWise,
     IsUninst and the like). I use a simple ShellExecute for that,
     and it works for most cases. I haven´t figured out (yes, call me
     lazy!) exactly how Windows did it (CreateProcess maybe?)

   IF you have questions/problems/suggestions with the
   presented code, please contact me through e-mail at
   simonet@bhnet.com.br

   Yours,

   Alex
   Belo Horizonte, 4 de Abril de 2000

*)


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    ListView1: TListView;
    Bevel1: TBevel;
    btRead: TButton;
    Button2: TButton;
    Bevel2: TBevel;
    btUninst: TButton;
    Bevel3: TBevel;
    Button5: TButton;
    Label1: TLabel;
    Label2: TLabel;
    btRemove: TButton;
    StatusBar1: TStatusBar;
    procedure btReadClick(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure btRemoveClick(Sender: TObject);
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure Button2Click(Sender: TObject);
    procedure btUninstClick(Sender: TObject);
  private
  procedure ReviewButtonsState(Enabled : boolean);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses Registry, ShellAPI;

const
UNINST_PATH = ´SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall´;


procedure TForm1.btReadClick(Sender: TObject);
var
li : TlistItem;
  Reg : TRegistry;
  SubKeys : TStringList;
  i : integer;
  DispName, UninstStr : string;
begin
Reg := TRegistry.create;
ReviewButtonsState(false);
  btRead.caption := ´Refresh information´;
  with Reg do
  try
  with ListView1.items do
     try
        beginupdate;
        clear;
        RootKey := HKEY_LOCAL_MACHINE;
        if OpenKeyReadOnly(UNINST_PATH) then
       begin
        SubKeys := TStringList.create;
           try
           GetKeyNames(SubKeys);
              CloseKey;
              for i := 0 to subKeys.count-1 do
              if OpenKeyReadOnly(Format(´¬s\¬s´, [UNINST_PATH, SubKeys[i]])) then
                    try
                    DispName := ReadString(´DisplayName´);
                       UninstStr := ReadString(´UninstallString´);
                       if DispName <> ´´ then
                       begin
                       li := add;
                          li.caption := DispName;
                          li.subitems.add(UninstStr);
                          li.subitems.add(SubKeys[i]);
                       end;
                    finally
                       CloseKey;
                    end;
finally
           SubKeys.free;
           end;
        end;
     finally
     ListView1.AlphaSort;
        endupdate;
     end ;
  finally
  closekey;
  free;
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
close;
end;

procedure TForm1.btRemoveClick(Sender: TObject);
const
BOX_TITLE = ´Remove uninstall information from Registry´;
var
Reg : TRegistry;
  Resp : word;
  li : TListItem;
  Success : boolean;
begin
Resp := application.messagebox(´Are you sure you want to remove this application´´s uninstalling information from the Registry?´+1013+´Doing so may prevent you from uninstalling the application at a later time. Please act with caution.´, BOX_TITLE, MB_YESNO + MB_ICONWARNING);
  if Resp<>IDYES then exit;
  Reg := TRegistry.create;
  with Reg do
  try
  li := ListView1.selected;
     RootKey := HKEY_LOCAL_MACHINE;
     Success := DeleteKey(Format(´¬s\¬s´, [UNINST_PATH, li.SubItems[1]]));
     if Success then
     begin
     application.messagebox(´Information successfully removed from the Registry.´, BOX_TITLE, MB_OK + MB_ICONEXCLAMATION);
        li.delete;
     end
     else
     application.messagebox(´There was an error removing the information from the Registry. Check your user rights.´, BOX_TITLE, MB_OK + MB_ICONERROR);
  finally
  closekey;
  free;
  end;

end;

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
btUninst.enabled := (ListView1.selected <> nil) AND (ListView1.selected.subitems[0]<>´´);
  btRemove.enabled := (ListView1.selected <> nil);
end;

procedure TForm1.ReviewButtonsState(Enabled : boolean);
begin
btUninst.enabled := Enabled;
  btRemove.enabled := Enabled;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
ShellAbout(handle, ´How to retrieve a list of installed applications´, ´Written by Alex Simonetti Abreu - simonet@bhnet.com.br´, Application.icon.handle);
end;

procedure TForm1.btUninstClick(Sender: TObject);
const
BOX_TITLE = ´Uninstall application´;
var
  Resp : word;
  Success : boolean;
  RunStr : string;
begin
Resp := application.messagebox(´Are you sure you want to uninstall this application?´, BOX_TITLE, MB_YESNO + MB_ICONWARNING);
  if Resp<>IDYES then exit;
  RunStr := ListView1.selected.subitems[0];
  ShellExecute(handle, ´open´, pchar(RunStr), nil, nil, SW_SHOW);
  {
  if Success then
  begin
     application.messagebox(´Information successfully removed from the Registry.´, BOX_TITLE, MB_OK + MB_ICONEXCLAMATION);
     li.delete;
  end
  else
     application.messagebox(´There was an error removing the information from the Registry. Check your user rights.´, BOX_TITLE, MB_OK + MB_ICONERROR);
}     
end;

end.



GOSTEI 0
Robsonjunior

Robsonjunior

15/08/2003

ei , desculpa e tal .. mas vc tem o projeto feito ja,

é pq eu nao to conseguindo fazer ....

se tiver , tem como me mandar no meu email ?

valew ..


robson_cruz_junior@hotmail.com


GOSTEI 0
POSTAR