Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

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
Avatar of tboy6423
tboy6423
Flag of United States of America image

Please take a look at the last post of this thread, this should help you:
http://bytes.com/forum/thread522485.html 
Avatar of John500

ASKER

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.
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...
Avatar of John500

ASKER

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......
Please follow the instructions here:
http://kbase.gfi.com/showarticle.asp?id=KBID002902
Avatar of John500

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of tboy6423
tboy6423
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John500

ASKER

No, I didn't and that was the problem.  Thanks!

How about taking a look at this question too please!

https://www.experts-exchange.com/questions/23872198/How-to-save-a-registry-key-value-to-string.html