Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Listar programas instalados (https://www.clubdelphi.com/foros/showthread.php?t=65132)

vroa74 23-11-2009 16:40:25

Listar programas instalados
 
hola: me tope con un codigo para lista los programas instalados en windows xp, mas este programa no me esta funcionando en windows vista, me interesa mucho que funcione.
Les pongo el codigo aqui
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
 const CLAVE =
   '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';

 var
   reg    : TRegistry;
   Lista  : TStringList;
   Lista2 : TStringList;
   i,n    : integer;

 begin
   mp.Clear;
   txtpcerrar.Clear;
   {Creamos temporales}
   reg    := TRegistry.Create;
   Lista  := TStringList.Create;
   Lista2 := TStringList.Create;

   {Cargamos todas las subkeys}
   {Load all the subkeys}
   with Reg do
   begin
     RootKey := HKEY_LOCAL_MACHINE;
     OpenKey(CLAVE,false);
     GetKeyNames(Lista);
   end;

   {Cargamos todos los Nombres de valores}
   for i := 0 to Lista.Count -1 do
   begin
     reg.OpenKey(CLAVE + '\' +Lista.Strings[i],false);
     reg.GetValueNames(Lista2);
     {Mostraremos sólo los que tengan 'DisplayName'}
     n:=Lista2.IndexOf('DisplayName');
     if (n <> -1) and (Lista2.IndexOf('UninstallString')<>-1) then
     begin
        {DisplayName+UnInstallString}
       Mp.Lines.Append (reg.ReadString(Lista2.Strings[n])+'    -    
            '+ reg.ReadString(Lista2.Strings Lista2.IndexOf('UninstallString')]));
     end;
   end;
   {Liberamos temporales}
   Lista.Free;
   Lista2.Free;
   reg.CloseKey;
   reg.Destroy;
end;

jhonny 23-11-2009 17:42:33

Realmente no he probado lo que voy a decir, pero intenta hacerlo de la siguiente manera y nos cuentas como te va:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
const CLAVE =
   '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';

 var
   reg    : TRegistry;
   Lista  : TStringList;
   Lista2 : TStringList;
   i,n    : integer;

 begin
   mp.Clear;
   txtpcerrar.Clear;
   {Creamos temporales}
   reg    := TRegistry.Create;
   Lista  := TStringList.Create;
   Lista2 := TStringList.Create;

   {Cargamos todas las subkeys}
   {Load all the subkeys}
   with Reg do
   begin
     RootKey := HKEY_LOCAL_MACHINE;
     OpenKeyReadOnly(CLAVE,false);
     GetKeyNames(Lista);
   end;

   {Cargamos todos los Nombres de valores}
   for i := 0 to Lista.Count -1 do
   begin
     reg.OpenKeyReadOnly(CLAVE + '\' +Lista.Strings[i],false);
     reg.GetValueNames(Lista2);
     {Mostraremos sólo los que tengan 'DisplayName'}
     n:=Lista2.IndexOf('DisplayName');
     if (n <> -1) and (Lista2.IndexOf('UninstallString')<>-1) then
     begin
        {DisplayName+UnInstallString}
       Mp.Lines.Append (reg.ReadString(Lista2.Strings[n])+'    -    
            '+ reg.ReadString(Lista2.Strings Lista2.IndexOf('UninstallString')]));
     end;
   end;
   {Liberamos temporales}
   Lista.Free;
   Lista2.Free;
   reg.CloseKey;
   reg.Destroy;
end;

Neftali [Germán.Estévez] 24-11-2009 14:00:42

1 Archivos Adjunto(s)
Estoy con un tema de WMI y esto creo (ahora lo se seguro) también se puede hacer utilizando "Windows Management Instrumentation". Para probarlo he realizado un ejemplo donde se vé cómo obtener la información.
La información completa y explicación detallada se puede ver aquí, aun así te adjunto el ejemplo.
Debes importar para ello, desde Delphi la librería: “Microsoft WMI Scripting v1.X Library (Version 1.X)“ de la forma estandard (ahí se explica cómo).

jhonny 24-11-2009 14:46:22

Ey Neftali, un tema muy interesante, gracias por ponerlo a disposición :).

Neftali [Germán.Estévez] 24-11-2009 16:10:08

Cita:

Empezado por jhonny (Mensaje 347315)
...un tema muy interesante.

Realmente a mi también me lo ha parecido. Actualmente estoy "peleándome" con el por cuestiones de trabajo, pero la verdad es que tiene muchas posibilidades.

Espero seguir ampliándolo en el blog.

Stereo100 19-04-2016 21:17:51

Buenas, habrá algo parecido para lazarus.

Casimiro Notevi 19-04-2016 23:50:35

Cita:

Empezado por Stereo100 (Mensaje 504490)
Buenas, habrá algo parecido para lazarus.

¿Lo has probado?


La franja horaria es GMT +2. Ahora son las 22:27:28.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi