3
Answers

How to gain access to a Registry Key and delete all subkeys

Photo of Dave Murphy

Dave Murphy

6y
1.9k
1
I need to gain access to this Registry key and delete all sub keys, but I keep getting a permission error
 
This is the actual Registry Key that I want to remove all the sub keys from:
 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles
 
This is the code that is throwing an error:
 
If I use this code, I get a permissions Error
 
RegistryKey aRegkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList", true);
 
If I add the profiles Key, i Get a Null reference:
 
RegistryKey aRegkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\Profiles", true);
 
I think I have to do something like this to get security permissions . . .
 
var security = aRegkey.GetAccessControl();
var rules = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
 
Any Help would be greatly appreciated :)) 

Answers (3)