Link to home
Start Free TrialLog in
Avatar of olegsp
olegsp

asked on

Creating HKEY_LOCAL_MACHINE entry

I need to create a registry entry in HKEY_LOCAL_MACHINE, which, in addition to its default properties, can be read by any user (including the restricted users). I am using CRegKey class with the following options

lResM = regKeyM.Create(HKEY_LOCAL_MACHINE, _T("Software\\Something"), REG_NONE,
                  REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_READ | KEY_WRITE);

if(lResM==ERROR_SUCCESS)
{
     lResM = regKeyM.QueryStringValue(pName, sValue, &dwSize);
}

Works fine for admins and power-users, but returns lResM=5 for restricted users (Windows XP), meaning "access denied". How can I read from this registry entry under restricted account?
Avatar of jkr
jkr
Flag of Germany image

>>How can I read from this registry entry under restricted account?

By using the appropriate access right. 'KEY_ALL_ACCESS | KEY_READ | KEY_WRITE' is a bit too much, since that's not only write access, but *full* acces.

lResM = regKeyM.Create(HKEY_LOCAL_MACHINE, _T("Software\\Something"), REG_NONE,
               REG_OPTION_NON_VOLATILE, KEY_READ);

should be and in fact is sufficiant.
Avatar of olegsp
olegsp

ASKER

Well, I also want admins and power users to be able to write in this key (and everybody else with restricted rights - just read), so they should have full access. I guess my question is: how do I provide read-only access to this key for restricted users, and full access for power users and admins?

Must work for any version of Windows, using registry.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial