Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
Microsoft.Win32.RegistryKey key; 
            key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\name");
            key.SetValue("test", "123");
            key.Close();
            return true;


By this code i want to create a subkey in Localmachine registry. but my system gives

Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\name' is denied. error.
I am using admin user . How i solve it
Posted
Updated 28-Oct-18 5:16am
Comments
Richard MacCutchan 3-Mar-15 3:44am    
Are you sure that your program is running with Administration privilege?
ErBhati 3-Mar-15 4:10am    
yes i m sure
Joan Magnet 3-Mar-15 6:10am    
Can you do it using regedit?
George Swan 3-Mar-15 8:38am    
It is not sufficient for you to be logged on as an administrator, you need to right click on the application and select 'Run as Administrator'
ErBhati 4-Mar-15 2:25am    
I run my application set up as 'Run as Administrator'. but i found same error.

"Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Test' is denied".

1 solution

As mentioned in comments, this is a permissions/user access issue and not a code issue.
 
Share this answer
 
Comments
ErBhati 4-Mar-15 2:26am    
I run my application set up as 'Run as Administrator'. but i found same error.

"Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Test' is denied".
ZurdoDev 4-Mar-15 7:32am    
You probably need to turn off UAC. See http://stackoverflow.com/questions/10151771/access-denied-when-creating-registry-key-in-c-sharp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900