home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kompon / d2345 / MSYSINFO.ZIP / Source / MSI_Software.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-21  |  2KB  |  95 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       MiTeC System Information Component              }
  5. {         Installed Software Detection Part             }
  6. {           version 5.4 for Delphi 3,4,5                }
  7. {                                                       }
  8. {       Copyright ⌐ 1997,2001 Michal Mutl               }
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. {$INCLUDE MITEC_DEF.INC}
  13.  
  14. unit MSI_Software;
  15.  
  16. interface
  17.  
  18. uses
  19.   SysUtils, Windows, Classes;
  20.  
  21. type
  22.   TSoftware = class(TPersistent)
  23.   private
  24.     FProducts: TStrings;
  25.   public
  26.     constructor Create;
  27.     destructor Destroy; override;
  28.     procedure GetInfo;
  29.     procedure Report(var sl :TStringList);
  30.   published
  31.     property Installed: TStrings read FProducts write FProducts stored false;
  32.   end;
  33.  
  34. implementation
  35.  
  36. uses Registry, MiTeC_Routines;
  37.  
  38. { TSoftware }
  39.  
  40. constructor TSoftware.Create;
  41. begin
  42.   FProducts:=TStringList.Create;
  43. end;
  44.  
  45. destructor TSoftware.Destroy;
  46. begin
  47.   FProducts.Free;
  48.   inherited;
  49. end;
  50.  
  51. procedure TSoftware.GetInfo;
  52. const
  53.   rk = {HKEY_LOCAL_MACHINE\}'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';
  54.   rv = 'DisplayName';
  55. var
  56.   i: integer;
  57.   sl: TStringList;
  58. begin
  59.   try
  60.  
  61.   FProducts.Clear;
  62.   with TRegistry.Create do
  63.     try
  64.       RootKey:=HKEY_LOCAL_MACHINE;
  65.       if OpenKey(rk,False) then begin
  66.         sl:=TStringList.Create;
  67.         GetKeyNames(sl);
  68.         CloseKey;
  69.         for i:=0 to sl.Count-1 do
  70.           if OpenKey(rk+'\'+sl[i],False) then begin
  71.             if ValueExists(rv) then
  72.               FProducts.Add(ReadString(rv));
  73.             CloseKey;
  74.           end;
  75.         sl.Free;
  76.       end;
  77.     finally
  78.       Free;
  79.     end;
  80.  
  81.   except
  82.     on e:Exception do begin
  83.       MessageBox(0,PChar(e.message),'TSoftware.GetInfo',MB_OK or MB_ICONERROR);
  84.     end;
  85.   end;
  86. end;
  87.  
  88. procedure TSoftware.Report(var sl: TStringList);
  89. begin
  90.   sl.Add('[Installed Software]');
  91.   StringsToRep(Installed,'Count','Item',sl);
  92. end;
  93.  
  94. end.
  95.