我的一个可执行文件将一些配置写入到 C:\Program Files\MyApp\config.xml 的 XML 文件中。它需要在 Vista / Server 2008 上以管理员身份运行,否则操作系统不会让它写入该位置。
我包含了一个名为 config.exe.manifest 的清单文件,以在启动时自动请求管理权限。
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
我在 Windows Server 2008 上试过这个,但清单文件似乎被忽略了,并且可执行文件在没有足够权限的情况下启动。