【问题标题】:How Do I Get System Account Permissions or run app with system rules in C#如何在 C# 中获取系统帐户权限或使用系统规则运行应用程序
【发布时间】:2015-10-27 16:04:30
【问题描述】:

我想从注册表 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();

此代码允许我删除除 PROPERTIES 之外的所有部分

我知道我需要获得系统权限才能执行此操作,但我不知道如何在代码中实现。 p.s. 我需要作为系统启动进程 像 PsExec,但在代码中

【问题讨论】:

    标签: c#


    【解决方案1】:
    1. 在具有管理员权限的新模拟线程中启动此代码:link
    2. 以管理员权限模拟当前线程:link

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 2020-04-10
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 2015-08-17
      • 2011-04-05
      • 2016-09-04
      相关资源
      最近更新 更多