Link to home
Start Free TrialLog in
Avatar of Darren Kattan
Darren KattanFlag for United States of America

asked on

C# Registry Permission can't Write to Registry

I'm trying to make a program that will write to a particular registry Key that "Everybody" doesn't have full control over.

Here's the basic Gyst of the code:
RegistryKey key2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\FTDIBUS\\VID_0403+PID_6001+5&138461b1&0&1\\0000", true);

This particular key inherits its security settings from the Enum Key.

If I run the same line without the true on the end, it goes past this line, but hangs whenever I try to write to the key.

I can successfully write to other keys/values with no problem.

Here's the kicker. If I go into RegEdit, I can set the permissions manually so that Everyone has Full Access to this key,  the program works without a hitch.

Currently only SYSTEM has Full Access.

I plan on deploying this to many computers, so I need a way for the program to Change the Permissions for that Key. I'm assuming if the person running the program has Admin Access, then I should be able to accomplish this.

I have tried inserting:
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, Write=@"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum")]

at the beginning, but that doesn't do anything.

I've fooled with with RegistryAccessRules, and I've made a Rule that will accomplish what I want, but I have no earthly idea how to apply that rule to the registry key if it isn't open in write mode (true at the end);

I would greatly appreciate any help at all with this.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
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
SOLUTION
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