1

I want to remove the sections from the registry System\CurrentControlSet\Enum\USB, but i cant delete PROPERTIES (windows10)

string user = Environment.UserDomainName + "\\" + Environment.UserName;
RegistrySecurity mSec = new RegistrySecurity();

RegistrySecurity mSec = new RegistrySecurity();

RegistryAccessRule newRule =
new RegistryAccessRule(
user,
RegistryRights.FullControl,
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow);

RegistryKey hkusb = hklm.OpenSubKey(RegistryPath, RegistryKeyPermissionCheck.ReadSubTree);

RegistrySecurity security = hkusb.GetAccessControl();
if (ContainsRule(security.GetAccessRules(true, true, typeof(SecurityIdentifier)), newRule))
{
Console.WriteLine("Access");
Console.ReadKey();
return;
}
security.AddAccessRule(newRule);

hkusb.SetAccessControl(security); <----error here
hkusb.Close();
showKeyTree(hkusb, "+");
Console.ReadKey();

this code allows me to delete all sections exept PROPERTIES

i understand that iam need to get a system permissions to do this, but i dont know how to make it in code. p.s. I need to start process as system like PsExec, but in code

frostazaza
  • 33
  • 1
  • 4

1 Answers1

0
  1. Start this code in new impersonate thread with admin privileges: link
  2. Impersonate current thread with admin privileges: link
Community
  • 1
  • 1
Evgeniy Mironov
  • 777
  • 6
  • 22