Registry access in non-admin mode

前端 未结 6 1252
暗喜
暗喜 2020-12-17 01:55

I\'ve several long-standing apps written in Delphi that persist their settings in the registry. I\'ve used HKEY_LOCAL_MACHINE for \'hard\' settings such as configuration pre

6条回答
  •  一向
    一向 (楼主)
    2020-12-17 02:47

    You can read from HKLM as a non-admin user; you just can't write to it.

    Use TRegistry.Create(KEY_READ) when constructing it, and set the RootKey to HKLM.

    var
      Reg: TRegistry;
    begin
      Reg := TRegistry.Create(KEY_READ)
      try
        Reg.RootKey := HKLM;
        // Read value here
      finally
        Reg.Free;
      end;
    end;
    

    You can also use TRegistry.OpenKeyReadOnly() when opening a specific registry key; this helps with non-admin access to areas of the registry as well.

提交回复
热议问题