Cannot write to the registry key

I'm getting the following error when I try to write to the Vista registry:

System.UnauthorizedAccessException was unhandled
  Message="Cannot write to the registry key."
  Source="mscorlib"
  StackTrace:
       at Microsoft.Win32.RegistryKey.EnsureWriteable()
       at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
       at RegistryCheck.Program.Main(String[] args) in C:\RegistryCheck\Program.cs:line 75
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

I'm runing Visual Studio as Administrator but this doesn't make a difference.  What am I missing - both for the sake of debug and as a final executable?

Thanks
John500Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

tboy6423Commented:
Please take a look at the last post of this thread, this should help you:
http://bytes.com/forum/thread522485.html 
0
John500Author Commented:
Thanks.  The last post goes like this:

Sorry if I wasn't clear, but you have to enable "registry object access"
auditing, that is from regedit select the key you want to audit and add the
user or group you want to monitor. Then, using "Local Security Policy"
editor, you must turn-on; Local Policies - Audit Policy - Audit Object
Access for Failure. When done, each unsuccessful access will be logged in
security log and will contain the account used to modify a key or subkey.

Can you interpret this for me?  How is this done?  The writer states the requirement but doesn't demonstrate it.
0
tboy6423Commented:
Try and disable the UAC first following these instructions:
http://www.mydigitallife.info/2006/12/19/turn-off-or-disable-user-account-control-uac-in-windows-vista/ 

This article also explains what vista changed regarding the administrator account...
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

John500Author Commented:
The UAC is turned off but this doesn't make a difference.  As I said, I'm also running Visual Studio as administrator.

The article doesn't talk about C# code or .Net provisions for this problem......
0
tboy6423Commented:
Please follow the instructions here:
http://kbase.gfi.com/showarticle.asp?id=KBID002902
0
John500Author Commented:
I don't get it - this article talks about enabling Auditing.  If you want to log the changes that occur on a particular item then these steps would apply but not to C# code that needs access to the registry.
0
tboy6423Commented:
This is an app your creating correct? Did you set the OpenSubKey() function to true ? (sorry about the other posts, got it confused with another answer I am working on :)
0

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
John500Author Commented:
No, I didn't and that was the problem.  Thanks!

How about taking a look at this question too please!

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23872198.html
0
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
.NET Programming

From novice to tech pro — start learning today.