Recent

Author Topic: Problem with registry key  (Read 188 times)

Roman

  • New Member
  • *
  • Posts: 16
Problem with registry key
« on: November 12, 2019, 03:16:11 pm »
I would like to control with Lazarus the screen resolution. I tried this code:

Code: Pascal  [Select]
  1.   reg:=Tregistry.Create(KEY_READ);
  2.   reg.RootKey:=HKEY_LOCAL_MACHINE;
  3.   reg.OpenKeyReadOnly(key);  

If the key is

Code: Pascal  [Select]
  1. SYSTEM\CurrentControlSet\Control\GraphicsDrivers

the key is opened successfully and key names and key values are obtained correctly. But if I try the key

Code: Pascal  [Select]
  1. SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration

 (only 'Configuration' added) the OpenKeyReadOnly returns false. Putting backslash before 'SYSTEM' doesn’t help. What am I doing wrong? (W10, Lazarus 2.0.6)
« Last Edit: November 12, 2019, 03:19:19 pm by Roman »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 681
    • Lebeau Software
Re: Problem with registry key
« Reply #1 on: November 12, 2019, 06:47:59 pm »
TRegistry has LastError and LastErrorMsg properties.  What do they report when OpenKeyReadOnly() returns false?  Chances are, either the key really does not exist, or you simply don't have permission to access it.
« Last Edit: November 13, 2019, 01:44:04 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Roman

  • New Member
  • *
  • Posts: 16
Re: Problem with registry key
« Reply #2 on: November 12, 2019, 09:05:37 pm »
You are right, 5 - Access is denied. Running as administrator solves problem. Thank you.