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?
 
tboy6423Connect With a Mentor Commented:
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.