我的猜测是setup.exe
正在触发UAC setup compatibility heuristic。从MSDN:
当检测应用程序安装包需要提升权限,用户被提示输入管理员用户名和密码。如果用户输入有效凭证,则操作将继续执行适用的权限。
Windows会尝试检测已安装程序(例如那些含有设置,安装,更新在其文件名),并会尝试自动提升他们的某些应用。微软确实这是一个兼容性黑客:
- 大多数用户都没有意识到他们应该用鼠标右键单击一个安装程序,并选择以管理员身份运行
- 甚至更少的开发人员正确地纪念他们的安装者requireAdministrator
- 甚至更少开发人员使用MSI,它知道如何/当/如果提升到管理员
您可以通知Windows您应用程序应该以管理员身份运行而不是。您可以通过将asInvoker
选项添加到您的可执行文件的程序集清单中来执行此操作:
<?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="client"
type="win32"
/>
<description>CodeJunkie Widget Installer</description>
<!-- Disable Setup elevation compatibility heuristics since we're named setup.exe -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>