Einzelnen Beitrag anzeigen

Benutzerbild von HomerGER
HomerGER

Registriert seit: 9. Jun 2003
390 Beiträge
 
Delphi 7 Professional
 
#2

Re: Registry: Binär-Wert auslesen

  Alt 26. Apr 2004, 19:19
guck mal hier

hier noch mal
Code:
{******************************************} 
{2. by Ralph Friedman } 


 Question:
 I want to read out the binary-value "problems" of the path
 HKEY_DYN_DATA\Config Manager\Enum\[add the key of a hardware component] to
 detect if a hardware component is troubled and not working right.
 But I cannot handle the ReadBinaryData-Method of TRegistry correct.
 Everytime I use it, it always returns "4" as content of the buffer.
 How do I detect if the content of the binary-key "problems" is
 not "00 00 00 00" but something else like "16 00 00 00" or such? 


{Answer: Here's an example of ReadBinaryData } 

procedure TFrmReadBinary.Button1Click(Sender: TObject);
const
  CKeyName: string = 'System\Setup';
  CValName: string = 'NetcardDlls';
var
  keyGood: boolean;
  p: integer;
  regKey: TRegistry;
  tmpStr: string;
  vSize: integer;
begin
  regKey := TRegistry.Create;
  try
    regKey.RootKey := HKEY_LOCAL_MACHINE;
    keyGood := regKey.OpenKey(CKeyName, False);

    if (keyGood) then
    begin
      vSize := regKey.GetDataSize(CValName);

      if (vSize > 0) then
      begin
        SetLength(tmpStr, vSize);
        regKey.ReadBinaryData(CValName, tmpstr[1], vSize);

        repeat
          p := Pos(#0, tmpStr);

          if p <> 0 then
          begin
            Delete(tmpStr, p, 1);
            Insert(#13#10, tmpStr, p);
          end;
        until p = 0;

        (*StringReplace(tmpStr, #0, #13#10, [rfReplaceAll]); *)

        ListBox1.Items.Text := tmpStr;
      end;
    end;
  finally
    regKey.Free;
  end;
end;

von den schweizerkollegen
  Mit Zitat antworten Zitat