Author: William Gerbert
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:
1 procedure TFrmReadBinary.Button1Click(Sender: TObject);
2 const3 CKeyName: string = 'System\Setup';
4 CValName: string = 'NetcardDlls';
5 var6 keyGood: boolean;
7 p: integer;
8 regKey: TRegistry;
9 tmpStr: string;
10 vSize: integer;
11 begin12 regKey := TRegistry.Create;
13 try14 regKey.RootKey := HKEY_LOCAL_MACHINE;
15 keyGood := regKey.OpenKey(CKeyName, false);
16 if (keyGood) then17 begin18 vSize := regKey.GetDataSize(CValName);
19 if (vSize > 0) then20 begin21 SetLength(tmpStr, vSize);
22 regKey.ReadBinaryData(CValName, tmpstr[1], vSize);
23 repeat24 p := Pos(#0, tmpStr);
25 if p <> 0 then26 begin27 Delete(tmpStr, p, 1);
28 Insert(#13#10, tmpStr, p);
29 end;
30 until31 p = 0;
32 {StringReplace(tmpStr, #0, #13#10, [rfReplaceAll]);}33 ListBox1.Items.Text := tmpStr;
34 end;
35 end;
36 finally37 regKey.Free;
38 end;
39 end;