2003. december 28., vasárnap

How to read binary values from the registry


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?


Here's an example of ReadBinaryData:

procedure TFrmReadBinary.Button1Click(Sender: TObject);
  CKeyName: string = 'System\Setup';
  CValName: string = 'NetcardDlls';
  keyGood: boolean;
  p: integer;
  regKey: TRegistry;
  tmpStr: string;
  vSize: integer;
  regKey := TRegistry.Create;
    regKey.RootKey := HKEY_LOCAL_MACHINE;
    keyGood := regKey.OpenKey(CKeyName, false);
    if (keyGood) then
      vSize := regKey.GetDataSize(CValName);
      if (vSize > 0) then
        SetLength(tmpStr, vSize);
        regKey.ReadBinaryData(CValName, tmpstr[1], vSize);
          p := Pos(#0, tmpStr);
          if p <> 0 then
            Delete(tmpStr, p, 1);
            Insert(#13#10, tmpStr, p);
          p = 0;
        {StringReplace(tmpStr, #0, #13#10, [rfReplaceAll]);}
        ListBox1.Items.Text := tmpStr;

Nincsenek megjegyzések:

Megjegyzés küldése