【问题标题】:Wix post-install and pre-uninstall executablesWix 安装后和卸载前可执行文件
【发布时间】:2019-04-11 04:49:47
【问题描述】:

我正在使用 wix 在 Visual Studio 中为我的应用程序创建安装程序。 我需要在安装(我已经开始工作)之后运行安装后可执行文件,并在卸载之前运行预卸载可执行文件。 所有这些可执行文件都需要提升权限才能运行(我的应用程序、安装后和卸载前)。

我搜索了网络和堆栈溢出,发现了许多与此相关的帖子,但似乎没有一个解决方案有效。可执行文件根本无法运行,或者在卸载时出现错误

There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor.

这是我的目录布局

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="ROOTDIRECTORY" Name="MyCompany" >
                <Directory Id="FOLDERONE" Name="FolderOne" />
                <Directory Id="UTILITYFOLDER" Name="Utility" />
            </Directory>
        </Directory>
    </Directory>
</Fragment>

还有我的文件布局的 sn-p

<Fragment>
    <DirectoryRef Id="UTILITYINSTALLFOLDER">
        <Component Id="cmpPreInstallId" Guid="{56DC3D0A-E887-4A94-95B3-72825310DC5D}">
            <File Id="filPreInstallId" KeyPath="yes" Source="path_to\PreUninstall.exe" />
        </Component>
        <Component Id="cmpPosUninstallId" Guid="{DE1DE45E-4D7C-4884-BA3E-EC078E265B7C}">
            <File Id="filPostUninstallId" KeyPath="yes" Source="path_to\PostInstall.exe" />
        </Component>
        <!-- obviously there are other files/components -->
    </DirectoryRef>
</Fragment>
<Fragment>
    <ComponentGroup Id="UtilityPublishedComponents">
        <ComponentRef Id="cmpPreInstallId" />
        <ComponentRef Id="cmpPosUninstallId" />
    </ComponentGroup>
</Fragment>

在我的 Product.wxs 中

<Product ...>

    <!-- The only way I found that actually worked to run the post install was -->
    <UI>
        <UIRef Id="WixUI_Minimal" />
        <Publish Dialog="ExitDialog"
               Control="Finish"
               Event="DoAction"
               Value="PostInstallExe">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Perform post-install operations." />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>
    <Property Id="WixShellExecTarget" Value="[#filPostUninstallId]" />
    <CustomAction Id="PostInstallExe"
                  BinaryKey="WixCA"
                  DllEntry="WixShellExec"
                  Impersonate="yes" />

    <!-- this does not work to run the pre-uninstall -->
    <CustomAction Id="EXECUTE_BEFORE_UNINSTALL"
                  Return="check"
                  Impersonate="yes"
                  Execute="immediate"
                  Directory="UTILITYINSTALLFOLDER"
                  ExeCommand="PreUninstall.exe" />
    <InstallExecuteSequence>
        <Custom Action="EXECUTE_BEFORE_UNINSTALL" Before="RemoveFiles">Installed AND NOT REINSTALL</Custom>
    </InstallExecuteSequence>

    <!-- other stuff plus the feature -->

</Product>

任何有经验的人都知道这可能会出错吗?

我已经尝试了 CustomAction 返回、模拟、执行等的许多变体

【问题讨论】:

    标签: wix


    【解决方案1】:

    终于让它工作了,所以希望这对某人有所帮助。 不知道问题是什么......但在这里!

    <!-- Setup post install operations -->
    <CustomAction Id="PostInstall"
                  FileKey="key_to_post_install_exe"
                  ExeCommand=""
                  Execute="deferred"
                  Return="check"
                  Impersonate="no" />
    
    <!-- Setup pre uninstall operations -->
    <CustomAction Id="PreUninstall"
                  FileKey="key_to_pre_uninstall_exe"
                  ExeCommand=""
                  Execute="deferred"
                  Return="ignore"
                  Impersonate="no" />
    
    <!-- Add pre and post install operations to the installer -->
    <InstallExecuteSequence>
      <Custom Action="PostInstall" Before="InstallFinalize">NOT Installed</Custom>
      <Custom Action="PreUninstall" After="InstallInitialize">Installed</Custom>
    </InstallExecuteSequence>
    

    【讨论】:

    • 这个答案有一个缺陷。安装产品,从 Programs and Features 运行 REPAIR,然后告诉我您的应用程序是否处于您期望的状态。
    • 在你修复了这个错误之后,这里是另一个。删除卸载 EXE 并执行卸载。您的卸载看起来会成功,但您的机器会不会像您期望的那样干净。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多