Wix 以管理员身份设置程序 运行

Wix set program run as admistrator

我已经将程序运行设置为windows启动,但是程序只能在运行作为管理员在windows10中运行,可以有人告诉我应该在代码中添加什么来设置它吗?这是我的 Wix 代码:

在产品模块中有

<ComponentRef Id="RegistryEntries"/>

然后

<Fragment>
    <DirectoryRef Id="ProgramFilesFolder">
      <Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
        <RegistryKey Root="HKCU"
                     Key="Software\Microsoft\Windows\CurrentVersion\Run"
              Action="createAndRemoveOnUninstall">
          <RegistryValue Type="string" Name="March Networks Video Assistant" Value="[INSTALLFOLDER]March Networks Video Assistant.exe" KeyPath="yes"/>          
        </RegistryKey>
      </Component>
    </DirectoryRef>
  </Fragment>

非常感谢大家。

问题是您将此注册表项放入 HKCU 中,这将在启动时 运行 当前用户上下文中的内容。

如果您希望它在启动时以管理员身份运行,则需要进入 HKLM。

尝试以下操作:

<Fragment>
  <DirectoryRef Id="ProgramFilesFolder">
    <Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
      <RegistryKey Root="HKLM"
                 Key="Software\Microsoft\Windows\CurrentVersion\Run"
          Action="createAndRemoveOnUninstall">
        <RegistryValue Type="string" Name="March Networks Video Assistant" Value="&quot;[INSTALLFOLDER]March Networks Video Assistant.exe&quot;" KeyPath="yes"/>          
      </RegistryKey>
    </Component>
  </DirectoryRef>
</Fragment>

所以请注意,我将 HKCU 更改为 HKLM(这可能会在编译期间导致 ICE 警告,但您可以安全地忽略它们)。如果您使用的是每个用户安装,我不知道这是否能够写入注册表项,除非安装是 运行 作为管理员...我还把 &quot; 放在您的 RegistryValue 周围值,因为由于有空格,最好将完整路径用引号引起来。

您可以做的另一件好事是使用组件的安装路径更新 RegistryValue 的值,可以使用以下语法引用该路径:

[#IDOfFile]

因此,如果您定义 "March Networks Video Assistant.exe" <File> 的组件使用 Id="MarchNetworksVideoAssistant.exe",您可以将 RegistryValue 的值更新为

value="&quot;[#MarchNetworksVideoAssistant.exe]&quot;"

你可以得到这个语法的很好的解释here

If a substring of the form [#filekey] is found, it is replaced by the full path of the file, with the value filekey used as a key into the File table. The value of [#filekey] remains blank and is not replaced by a path until the installer runs the CostInitialize action, FileCost action, and CostFinalize action. The value of [#filekey] depends upon the installation state of the component to which the file belongs. If the component is run from the source, the value is the path to the source location of the file. If the component is run locally, the value is the path to the target location of the file after installation. If the component has an action state of absent, the installed state of the component is used to determine the [#filekey] value. If the installed state of the component is also absent or null, [#filekey] resolves to an empty string, otherwise it resolves to the value based upon the component's installed state. For more information about checking the installation state of components, see Checking the Installation of Features, Components, Files.