Recent

Author Topic: [Solved] ReadBinaryData can't read DigitalProductId  (Read 4106 times)

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
[Solved] ReadBinaryData can't read DigitalProductId
« on: April 05, 2017, 09:08:22 pm »
Hi.
I am using
Windows 7 64 bit
Lazarus 1.6
FPC 3.0.0

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.   CompileCommand: string='';
  5.   Registry: TRegistry;
  6.   ms: TMemoryStream;
  7. begin
  8.   Registry := TRegistry.Create;
  9.   ms := TMemoryStream.Create;
  10.   Memo1.Lines.Clear;
  11.   try
  12.     Registry.RootKey := HKEY_LOCAL_MACHINE;
  13.     if Registry.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows NT\CurrentVersion\') then
  14.       begin
  15.         Memo1.Lines.Add(Registry.ReadString('ProductName'));
  16.         Memo1.Lines.Add(Registry.ReadString('EditionID'));
  17.         Memo1.Lines.Add(Registry.ReadString('BuildLab'));
  18.         Memo1.Lines.Add(Registry.ReadString('CurrentType'));
  19.         ms.Size:=Registry.GetDataSize('DigitalProductId');
  20.         Registry.ReadBinaryData('DigitalProductId',ms.Memory^, ms.Size);
  21.         Memo1.Lines.Add(DecodeProductKey(ms.ReadByte));
  22.       end;
  23.  
  24.   finally
  25.     Registry.Free;
  26.     ms.free;
  27.   end;
  28.  
  29.  

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
« Last Edit: April 06, 2017, 05:28:29 pm by TheLastCayen »

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: ReadBinaryData can't read DigitalProductId
« Reply #1 on: April 05, 2017, 10:02:03 pm »
Size for DigitalProductId4, but read DigitalProductId.

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Re: ReadBinaryData can't read DigitalProductId
« Reply #2 on: April 06, 2017, 04:49:56 pm »
Size for DigitalProductId4, but read DigitalProductId.

Thank you , good catch but that was only the result of previous test. I tried to read the other key with the same result. I fix the code and I still have the same error message. Any other recommendation ?

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Re: ReadBinaryData can't read DigitalProductId
« Reply #3 on: April 06, 2017, 05:28:03 pm »
I upgrade to
Lazarus: 1.6.4
FPC: 3.0.2

And now my code is working. Thank you

 

TinyPortal © 2005-2018