Hi.
I am using
Windows 7 64 bit
Lazarus 1.6
FPC 3.0.0
procedure TForm1.Button1Click(Sender: TObject);
var
CompileCommand: string='';
Registry: TRegistry;
ms: TMemoryStream;
begin
Registry := TRegistry.Create;
ms := TMemoryStream.Create;
Memo1.Lines.Clear;
try
Registry.RootKey := HKEY_LOCAL_MACHINE;
if Registry.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows NT\CurrentVersion\') then
begin
Memo1.Lines.Add(Registry.ReadString('ProductName'));
Memo1.Lines.Add(Registry.ReadString('EditionID'));
Memo1.Lines.Add(Registry.ReadString('BuildLab'));
Memo1.Lines.Add(Registry.ReadString('CurrentType'));
ms.Size:=Registry.GetDataSize('DigitalProductId');
Registry.ReadBinaryData('DigitalProductId',ms.Memory^, ms.Size);
Memo1.Lines.Add(DecodeProductKey(ms.ReadByte));
end;
finally
Registry.Free;
ms.free;
end;
Compiler can compile the code but when I execute it as normal user and administrator, I get this error message:
Failed to get data for value "DigitalProductId".
I know DigitalProductId exist in the registry but I don't know if this is an issue with my code or a weird windows security feature but "Registry.ReadBinaryData('DigitalProductId',ms.Memory^, ms.Size); " seem to be the problem.
Thank you