【问题标题】:How can I run a batch command with UAC administrator privilegies at WiX config如何在 WiX 配置中使用 UAC 管理员权限运行批处理命令
【发布时间】:2013-07-20 17:06:46
【问题描述】:

我的 UAC 权限有问题,这是我的配置:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define ProductName="AXClpb" ?>
  <?define ProductVersion="1.0.0.0" ?>
  <?define ProductCode="*"?>
  <?define UpgradeCode="7352E479-0BEA-4055-B9E1-9699195DA4FB"?>
  <?define Manufacturer="Aeroclub"?>

  <Product Id="$(var.ProductCode)" Name="$(var.ProductName)" Language="1049" Version="$(var.ProductVersion)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
    <Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" InstallScope="perMachine" />
    <Media Id="1" Cabinet="AXClpb.cab" EmbedCab="yes" />

    <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
    <Upgrade Id="$(var.UpgradeCode)">
      <UpgradeVersion
         Minimum="1.0.0.0" Maximum="99.0.0.0"
         Property="PREVIOUSVERSIONSINSTALLED"
         IncludeMinimum="yes" IncludeMaximum="no" />
    </Upgrade>

    <InstallExecuteSequence>
      <RemoveExistingProducts Before="InstallInitialize" />
      <Custom Action="RegisterClipboardActiveX" Before="InstallFinalize">Installed</Custom>
      <Custom Action="UnregisterClipboardActiveX" Before="RemoveFiles">Installed</Custom>
    </InstallExecuteSequence>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="ManufacturerFolder" Name="$(var.Manufacturer)">
          <Directory Id="INSTALLLOCATION" Name="$(var.ProductName)">
            <Component Id="ProductComponent1" Guid="A85287B1-2589-499E-91BD-83245242A648">
              <File Id='ClipboardActiveXDLL' Name='ClipboardActiveX.dll' Source='..\ClipboardActiveX\bin\Release\ClipboardActiveX.dll' Vital='yes' />
              <File Id='SetupInf' Name='setup.inf' Source='setup.inf' Vital='yes' />
              <RemoveFolder Id="INSTALLLOCATION" On="uninstall" />
            </Component>

            <Directory Id="Regasm" Name="Regasm">
              <Component Id="ProductComponent2" Guid="BC68B576-232D-42E1-AE82-DC2BF8A170F1">
                <File Id='RegAsmExe' Name='RegAsm.exe' Source='regasm\RegAsm.exe' Vital='yes' />
                <File Id='RegAsmExeConfig' Name='RegAsm.exe.config' Source='regasm\RegAsm.exe.config' Vital='yes' />
              </Component>
            </Directory>

            <Directory Id="Elevation" Name="Elevation">
              <Component Id="ProductComponent3" Guid="728D7ADD-E122-4289-A8A9-F2D482743EB5">
                <File Id='Elevate32Exe' Name='Elevate32.exe' Source='elevation\Elevate32.exe' Vital='yes' />
                <File Id='Elevate64Exe' Name='Elevate64.exe' Source='elevation\Elevate64.exe' Vital='yes' />
                <File Id='IsElevated32Exe' Name='IsElevated32.exe' Source='elevation\IsElevated32.exe' Vital='yes' />
                <File Id='IsElevated64Exe' Name='IsElevated64.exe' Source='elevation\IsElevated64.exe' Vital='yes' />
              </Component>
            </Directory>
          </Directory>
        </Directory>
      </Directory>
    </Directory>

    <CustomAction Id="RegisterClipboardActiveX" Directory="INSTALLLOCATION" ExeCommand="[SystemFolder]cmd.exe /C start start.bat" Return="check" Impersonate="no" Execute="deferred" />
    <CustomAction Id="UnregisterClipboardActiveX" Directory="INSTALLLOCATION" ExeCommand="[SystemFolder]cmd.exe /C start RegAsm.exe ClipboardActiveX.dll /u " Return="asyncNoWait" Impersonate="no" Execute="deferred" />

    <Feature Id="ProductFeature" Title="ClipboardActiveX" Level="1">
      <ComponentRef Id="ProductComponent1" />
      <ComponentRef Id="ProductComponent2" />
      <ComponentRef Id="ProductComponent3" />
    </Feature>
  </Product>
</Wix>

任何人都可以为我提供完整的答案,如何使用 UAC 管理员权限运行我的自定义操作?

我知道 elevate.exe,但我寻找更优雅的方式来做到这一点。

非常感谢您的帮助!

UPDATE1:将所有组件拆分为多个组件

【问题讨论】:

    标签: wix installation cmd uac regasm


    【解决方案1】:

    这不是您问题的答案,但它应该可以帮助您编写安装程序...

    首先,您应该考虑以下几点:

    • RegAsm.exe 可能未获得按您的方式分发的许可。
    • 组件通常应该有零个或一个文件元素。阅读组件设计和“组件规则”;开始here
    • 应通过标准 Windows Installer 表和操作更改注册表,而不是通过在 Windows Installer 跟踪之外运行的可执行文件。只要有可能,注册表更改应该与正在注册的文件在同一个组件中 - 这样,它们肯定会一起来去。

    WiX 的heat 工具将为 .NET 程序集生成创作。如果您使用 Visual Studio 和/或 MSBuild 来运行 WiX,则可以使用 HarvestFile 或 HarvestProject 技术(请参阅文档)。

    或者,通过命令行:

    heat file ..\ClipboardActiveX\bin\Release\ClipboardActiveX.dll -out ClipboardActiveX.wxs
    

    heat project ..\ClipboardActiveX\ClipboardActiveX.csproj -out ClipboardActiveX.wxs
    

    【讨论】:

    • 感谢您的回答,我在星期一查看了我的代码,但是您知道如何处理加热和重新充气 /tlb 选项吗?我需要 ClipboardActiveX.dll 和 ClipboardActiveX.tlb 文件才能成功注册我的库
    • Heat 检查文件以确定它是否需要各种类型的注册。它将自动生成从 .NET 程序集导出的 COM 服务器所需的注册表项。 (如果您要求的是 .tlb 文件,您的用户可能不需要此文件。)
    猜你喜欢
    • 2019-10-15
    • 2016-07-24
    • 1970-01-01
    • 2011-01-06
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多