如何在没有管理员权限的情况下执行此代码?
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
}
答案 0 :(得分: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>