Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i need some codes or another way to change the registry values under HKLM.
When i try it throws exceptions about authority. However my program is running under admin credentials. Here is my code:

C#
void test()
{
    string reg_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\abc";

    RegistryKey reg = Registry.LocalMachine.OpenSubKey(reg_key);

    reg.OpenSubKey("test").SetValue("State", "1"); 
}

I can do it manually but i need to do it programmatically. So how can i do?
Posted
Updated 20-Aug-13 2:30am
v5
Comments
Joezer BH 20-Aug-13 8:16am    
Copy the exact exception so that we understand better.
umutx 20-Aug-13 8:21am    
Exceptions:
"UnauthrizedAccessException was caught "
and when i change
OpenSubKey("test") to
OpenSubKey("test", true) it throws "SecurityException was caught"
Joezer BH 20-Aug-13 8:23am    
That's what I thought, then see the link I posted in the answer... It looks like UAC issues.
** I have updated your question to contain that in the title.
umutx 20-Aug-13 8:27am    
But i already have UAC issues and my program has admin credentials.
Joezer BH 20-Aug-13 8:30am    
What you mean by "I already have UAC issues"?

1 solution

In case you are having UAC issues, see if this [^]helps

Cheers,
Edo
 
Share this answer
 
v2

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