Posted on 2004-11-11
Last Modified: 2013-11-20
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?
Question by:olegsp
    LVL 86

    Expert Comment

    >>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.
    LVL 1

    Author Comment

    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.
    LVL 43

    Accepted Solution

    Try to open with write access, if it fails then the user doesn't have enough rights and then open with read access.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Perl Awk Need Help 3 85
    fizzArray2 challenge 1 44
    haveThree challenge 22 89
    Sed question 2 27
    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now