-2

如何在没有管理员权限的情况下执行此代码?

RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");

private void button1_Click(object sender, EventArgs e)
{
    key.SetValue("DisableTaskMgr", 1); 
}

private void button2_Click(object sender, EventArgs e)
{
    Registry.CurrentUser.DeleteSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
    // Or you can change the key value to 0
}
4

1 回答 1

1

您可以创建一个清单文件并添加以下代码,这会将您的程序提升到更高的特权模式。因此,您可以执行该程序。

1. Add a new file to you project called App.manifest; by adding a new File from 
   Project.
2. Add following data to that file, rest it will do the magic.

只需将您的应用程序名称替换为 YourAssemblyName。重要的部分是部分。休息是自动生成的。

<?xml version="1.0" encoding="utf-8" ?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
    xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
    xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="YourAssemblyName" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator"
        uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>
于 2013-05-18T08:45:08.917 回答