我想从注册表System \ CurrentControlSet \ Enum \ USB中删除这些部分,但我无法删除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();
此代码允许我删除exept属性的所有部分
我知道我需要获得系统权限才能执行此操作,但我不知道如何在代码中创建它。 附: 我需要开始进程作为系统 像PsExec,但在代码