?
Solved

Cannot write to the registry key

Posted on 2008-11-03
8
Medium Priority
?
1,168 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:John500
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:tboy6423
ID: 22870666
Please take a look at the last post of this thread, this should help you:
http://bytes.com/forum/thread522485.html 
0
 

Author Comment

by:John500
ID: 22870850
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
 
LVL 10

Expert Comment

by:tboy6423
ID: 22870930
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:John500
ID: 22871222
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
 
LVL 10

Expert Comment

by:tboy6423
ID: 22871251
Please follow the instructions here:
http://kbase.gfi.com/showarticle.asp?id=KBID002902
0
 

Author Comment

by:John500
ID: 22871406
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
 
LVL 10

Accepted Solution

by:
tboy6423 earned 2000 total points
ID: 22871441
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
 

Author Comment

by:John500
ID: 22871600
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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question