Dave Murphy

Dave Murphy

  • 1.9k
  • 14
  • 708

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

Aug 12 2018 1:08 PM
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)