none
C# Full Registry Access RRS feed

  • Question

  • How to get full access to the registry HKLM using windows forms?

    For Example:

    I can not write value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
                    if (key != null)
                    {
                        key.SetValue("DefaultUserName", "UserName", RegistryValueKind.String);
                        key.Close();
                    }

    Does not work either:

     Process regeditProcess = Process.Start("regedit.exe", "/s " + scryptPath);
                regeditProcess.WaitForExit();

    I run the Application as an Administrator

    Friday, September 21, 2018 7:20 PM

Answers

  • It may be dependent on a policy e.g. in my company it's forbidden to read and write to the registry no matter if one was to elevate permissions. If this is solely on your computer then you should not need to do anything while on other's computers this is not always the case as mentioned above. 

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by msoftx Sunday, September 30, 2018 6:39 PM
    Saturday, September 22, 2018 1:02 AM
    Moderator
  • Hi msoftx,

    Thank you for posting here.

    Based on my search, here is a similar thread in StackOverFlow for your reference. 

    https://stackoverflow.com/questions/34639084/access-to-the-registry-key-is-denied-when-i-want-update-the-value

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, September 27, 2018 6:17 AM
    • Marked as answer by msoftx Sunday, September 30, 2018 6:39 PM
    Monday, September 24, 2018 6:00 AM
    Moderator

All replies

  • It's not enough to run the application under a user account that is a member of the Administrator's group.  In order to obtain write access to HKLM the application must run elevated.

    Edit:

    Your application needs a manifest that has -

            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

    • Edited by RLWA32 Friday, September 21, 2018 7:46 PM added info
    Friday, September 21, 2018 7:26 PM
  • It may be dependent on a policy e.g. in my company it's forbidden to read and write to the registry no matter if one was to elevate permissions. If this is solely on your computer then you should not need to do anything while on other's computers this is not always the case as mentioned above. 

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by msoftx Sunday, September 30, 2018 6:39 PM
    Saturday, September 22, 2018 1:02 AM
    Moderator
  • Hi msoftx,

    Thank you for posting here.

    Based on my search, here is a similar thread in StackOverFlow for your reference. 

    https://stackoverflow.com/questions/34639084/access-to-the-registry-key-is-denied-when-i-want-update-the-value

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, September 27, 2018 6:17 AM
    • Marked as answer by msoftx Sunday, September 30, 2018 6:39 PM
    Monday, September 24, 2018 6:00 AM
    Moderator