1

我的安装程序部署了一个配置 exe,用于在也安装的 Windows 服务上进行一些基本配置。该exe还需要创建和编写一些注册表项。在 Windows server 2008 环境中,无法创建这些密钥。我调查并发现这是一个管理员权限,并且 exe 没有提示输入 2008 年 UAC 下所需的管理员权限。我可以通过右键单击 exe 并以管理员身份运行来解决此问题。这并不理想,但是因为它是我需要通知我们的客户执行的额外步骤。运行exe时还有其他方法可以提升管理员权限吗?

4

1 回答 1

1

将清单放在 exe 上或与 exe 一起。如果您让我知道您使用的是哪个版本,我可以告诉您如何使用 Visual Studio 嵌入清单。如果您没有使用 Visual Studio,或者您没有构建 exe,那么您可以将清单文件放在与 exe 相同的文件夹中,这也可以。在这种情况下,该文件必须与您的 exe 命名相同,并以 .manifest 结尾,例如对于 foo.exe,它是 foo.exe.manifest。内容应如下所示:

<?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="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

请注意,requestExecutionLevel 的可能值都在评论中,并且这个使用 requireAdministrator。现在它总是会提升并因此为您工作。

于 2010-06-04T10:24:21.213 回答