Fakedo0r

EnumInstalledPrograms

Apr 18th, 2012
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.98 KB | None | 0 0
  1. //******************************************************************************
  2. //* UNIT:         UNT_EnumInstalledPrograms
  3. //* AUTOR:        Fakedo0r
  4. //* FECHA:        19.04.2012
  5. //* CORREO:       [email protected]
  6. //* BLOG:         Sub-Soul.blogspot.com
  7. //* USO:          EnumPrograms(' : ');
  8. //******************************************************************************
  9. Unit UNT_EnumInstalledPrograms;
  10. //******************************************************************************
  11. //DECLARACION DE LIBRERIAS / CLASES
  12. //******************************************************************************
  13. Interface
  14.  
  15. Uses
  16.   Winapi.Windows, System.SysUtils, Vcl.Dialogs;
  17. //******************************************************************************
  18. //DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  19. //******************************************************************************
  20. Function EnumPrograms(sDelimitador: String): String;
  21. //******************************************************************************
  22. Implementation
  23. //******************************************************************************
  24. //<--- ENUMERA LOS PROGRAMAS INSTALADOS JUNTO A SUS UNINSTALL's --->
  25. //******************************************************************************
  26. Function EnumPrograms(sDelimitador: String): String;
  27. Var
  28.   ihKey:          HKEY;
  29.   ihSubKey:       HKEY;
  30.   dwIndex:        DWORD;
  31.   dwName:         DWORD;
  32.   dwDataSize:     DWORD;
  33.   pszName:        PChar;
  34.   sProName:       String;
  35.   sProPath:       String;
  36.   iRegType:       Integer;
  37.   tLastWriteTime: FileTime;
  38. Begin
  39.   dwIndex := 0;
  40.   dwName := 0;
  41.   dwDataSize := 0;
  42.   iRegType := 1;
  43.  
  44.   If RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall', 0, KEY_ENUMERATE_SUB_KEYS, ihKey) = ERROR_SUCCESS Then;
  45.   Begin
  46.     dwName := 255;
  47.     GetMem(pszName, dwName);
  48.  
  49.     While RegEnumKeyEx(ihKey, dwIndex, @pszName[0], dwName, Nil, Nil, Nil, @tLastWriteTime) = ERROR_SUCCESS do
  50.     Begin
  51.       Inc(dwIndex);
  52.       dwName := 255;
  53.  
  54.       If RegOpenKeyEx(ihKey, pszName, 0, KEY_QUERY_VALUE, ihSubKey) = ERROR_SUCCESS Then
  55.       Begin
  56.  
  57.         If RegQueryValueEx(ihSubKey, 'DisplayName', Nil, @iRegType, Nil, @dwDataSize) = ERROR_SUCCESS Then
  58.         Begin
  59.           SetLength(sProName, dwDataSize);
  60.           RegQueryValueEx(ihSubKey, 'DisplayName', Nil, @iRegType, PByte(PChar(sProName)), @dwDataSize);
  61.  
  62.           sProName := TrimA(sProName);
  63.  
  64.           If RegQueryValueEx(ihSubKey, 'UninstallString', Nil, @iRegType, Nil, @dwDataSize) = ERROR_SUCCESS Then
  65.           Begin
  66.  
  67.             If iRegType = REG_SZ Then
  68.             Begin
  69.               SetLength(sProPath, dwDataSize);
  70.               RegQueryValueEx(ihSubKey, 'UninstallString', Nil, @iRegType, PByte(PChar(sProPath)), @dwDataSize);
  71.  
  72.               sProPath := Trim(sProPath);
  73.  
  74.               Result := Result + sProName + sDelimitador + sProPath + #13#10;
  75.             End;
  76.           End;
  77.         End;
  78.       End;
  79.     End;
  80.   End;
  81. End;
  82. End.
Advertisement
Add Comment
Please, Sign In to add comment