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,

     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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>>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,

should be and in fact is sufficiant.
olegspAuthor Commented:
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.
AndyAinscowFreelance programmer / ConsultantCommented:
Try to open with write access, if it fails then the user doesn't have enough rights and then open with read access.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.