Get a list of the harware installed  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 08/05/00

Tip accessed 502 times

 


Get from alt.comp.lang.borland-delphi newsgroup
Author: alanglloyd@aol.com

Simply... reading it from the registry.

  • Add Registry in the uses of your form
  • Add a TMemo (Memo1) and a TButton
  • Put this code in the OnClick of TButton:



     procedure TForm1.Button1Click(Sender: TObject);
    
       procedure GetHardwareList(DisplayStrings : TStrings);
       var
         RegHKDD, RegHKLM: TRegistry;
         SLKeys, SLHWL: TStringList;
         i: Integer;
         RegDataInfo : TRegDataInfo;
       begin
         try
           RegHKDD := TRegistry.Create;
           RegHKDD.RootKey := HKEY_DYN_DATA;
           RegHKLM := TRegistry.Create;
           RegHKLM.RootKey := HKEY_LOCAL_MACHINE;
           SLKeys := TStringList.Create;
           SLHWL := TStringList.Create;
           SLHWL.Sorted := true;
           if RegHKDD.OpenKey('\Config Manager\Enum', false) then begin
             RegHKDD.GetKeyNames(SLKeys);
             for i := 0 to SLKeys.Count - 1 do
               if RegHKDD.OpenKey('\Config Manager\Enum\' + SLKeys[i], false)then
                 if RegHKLM.OpenKey('\Enum\' + RegHKDD.ReadString('HardWareKey'), false) then
                   if RegHKLM.GetDataInfo('Class', RegDataInfo) then
                     SLHWL.Add(RegHKLM.ReadString('Class')
                                   + ': '
                                   + RegHKLM.ReadString('DeviceDesc'));
           end; {if RegHKDD.OpenKey('\Config Manager\Enum', false)}
         finally
           SLKeys.Free;
           RegHKLM.Free;
           RegHKDD.Free;
         end;
         DisplayStrings.Assign(SLHWL);
         SLHWL.Free;
       end;
    
     begin
       GetHardwareList(Memo1.Lines);
     end;