我需要以管理员权限运行我的.exe。我搜索了谷歌,找到了我需要放入app.config文件中的xml片段。这是xml
:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="My Application" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"/>
</requestedPrivileges>
</security>
这足以以admin
权限运行任何exe
吗?。 谢谢。
是的,但是requestExecutionLevel 元素部分只是前半部分。如果 UAC 已关闭,则必须执行权限检查,如果用户不是管理员,则必须显示错误对话框。您可以使用 WindowsPrincipal.IsInRole 方法获取权限。
要创建运行方式...对话框看看这个:http://www.codeproject.com/Articles/7168/RunAs-Class