Jonathan D
Jonathan D

Reputation: 1364

Registry security settings

I’m trying to access a certain bit of the registry however it keeps returning null when i try to open it.

However i know the location is correct because i can navigate to it in reedit.

here’s my line of code for trying to access it.

Microsoft.Win32.RegistryKey RK = Microsoft.Win32.Registry.LocalMachine.OpenSubK("Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", false);

any one got any ideas?

update

it looks like i am seeing a different version fo the registery, this need to be a 32bit app but it needs to be able to see the 32bit and 64bit version of the registery.

Thank you

Upvotes: 2

Views: 1087

Answers (3)

ali
ali

Reputation: 195

 var tempKey = Registry.LocalMachine;

and for Security access

var rule = new RegistryAccessRule(LOGON_USER_NAME, RegistryRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
var security = new RegistrySecurity();
security.AddAccessRule(rule);
tempKey.SetAccessControl(security);

 tempKey = tempkey.OpenSubKey(SUB_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);

and for LOGON_USER_NAME

1)

var LOGON_USER_NAME = Environment.UserName;

2)

var LOGON_USER_NAME = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Upvotes: 1

Alex Dresko
Alex Dresko

Reputation: 5203

How is your application being run? In other words, what context does your application run under? Is it being run by double clicking on the .exe or is a setup application firing up the process? Setup applications run under a different context than you would expect.

Upvotes: 0

t0mm13b
t0mm13b

Reputation: 34592

Did you apply permissions to access the registry key via the attribute [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.RegistryPermission)] or are you running the program as administrator? Here's a detailed look at the Security Permissions as per MSDN, more aptly RegistryPermission

Upvotes: 1

Related Questions