Security Exception When Trying to Acess Registry


Well-known member
Jul 5, 2010
Programming Experience
I'm putting a little windows forms application together using VS2012 on a x64 machine. I'm at the very early stages and I'm testing getting values from the registry.

I have manually written some entries into the registry for testing, but I'm having trouble seeing them when I test my application. I understand this is due to differences in registry access when using x86 or x64 systems.

I have my project settings set to any CPU under the target cpu in the compile section of the project properties. There is also a checkbox for "Prefer 32-Bit". When this is checked, I can read from the registry, except for the values I entered manually. When I uncheck the prefer 32-bit box I get errors. The error occurs when I try and open any sub key using "Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft", True)"
"System.Security.SecurityException' occurred in mscorlib.dll
Requested registry access is not allowed."

Strange things is I dropped the project into Dropbox so I could test at work (also on a x64 machine) and everything was fine. By unchecking the prefer 32-bit checkbox I could read all the registry, including the ones I had created manually.

It is clearly an issue with permissions. At work I'm on a domain and using a domain admin account. At home I'm using an admin account on the local machine which is part of a workgroup. Could the project residing in dropbox affect the permission? I've tried dragging in back into My Documents but I'm still getting the same errrors.

All the help I can find relates to ASP.NEt pages throwing these errors in relation to writing to eventlogs, but this isn't relevant to my forms application. Any suggestions would be appreciated.
Top Bottom