【问题标题】:How wix uninstaller(exe) can remove itselfwix卸载程序(exe)如何删除自身
【发布时间】:2018-05-02 14:41:59
【问题描述】:

我有我的自定义安装程序和卸载程序,可以将 MSI 和其他资源安装到 PC。卸载过程在以下几行中运行:

<DirectoryRef Id="TARGETDIR">
    <Component Id="AddRemovePrograms" Guid="*" KeyPath="yes">
      <RegistryValue Id="ARPEntry1" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="DisplayName" Value="$(var.ProductName)"/>
      <RegistryValue Id="ARPEntry2" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="DisplayVersion" Value="$(var.ProductVersion)"/>
      <RegistryValue Id="ARPEntry3" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="Publisher" Value="$(var.Manufacturer)"/>
      <RegistryValue Id="ARPEntry4" Type="integer" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="NoModify" Value="1"/>
      <RegistryValue Id="ARPEntry5" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="UninstallString" Value="[CommonAppDataFolder]\[Manufacturer]\[ProductName]\Uninstaller.exe"/>
      <RegistryValue Id="ARPEntry6" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="InternalVersion" Value="$(var.ProductVersion)"/>
    </Component>
    <Directory Id="CommonAppDataFolder">
      <Directory Id="UninstallCompanyDir" Name="$(var.Manufacturer)">
        <Directory Id="UninstallProductDir" Name="$(var.ProductName)">
          <Component Id="UninstallerExe" Guid="*">
            <File Id="UninstallerExeFile" Name="Uninstaller.exe" Source="..\Uninstaller.exe" Vital="yes" KeyPath="yes">
            </File>
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </DirectoryRef>  

在 Uninstaller.exe 中,我将自身复制到 TEMP 文件夹并从那里运行它,但问题是我的卸载程序留在了那里(在 TEMP 中)。

问题: 如何使用 wix 脚本删除我的可执行文件(来自 TEMP 或原始文件)?

【问题讨论】:

  • 虽然无关紧要。但是黑客是可能的。创建一个批处理文件并从那里调用卸载程序。卸载完成后,批处理文件可以自行删除。

标签: c# wix uninstallation windows-installer


【解决方案1】:

你可以用批处理来做到这一点!

类似

cmd.exe /C TIMEOUT 10 && del "{your uninstaller path}"

您在卸载程序关闭事件中运行它。这将产生一个新的 cmd 进程并在 10 秒后执行删除命令。

【讨论】:

  • 是的,谢谢,它有帮助,但是更改命令行,那里需要参数 /C,不能这样做,因为编辑应该有超过 6 个符号
【解决方案2】:

对于这种情况,有一个文档化的“操作方法”,它不需要您拥有可执行文件,使用 msiexec.exe 而不是您自己的可执行文件:

How To: Create an Uninstall Shortcut

除了调用卸载之外,您没有说您的 exe 是否执行任何其他操作,但是 IMO 完全可以接受复制到临时文件夹并将可执行文件保留在那里(并且它不需要是 exe,因为您可以调用CreateProcess 作为 .tmp 文件)。有一些标准工具可以清除临时文件夹(磁盘清理、服务器脚本),所以不用担心。

通常,从 Windows 10 开始,您不需要在开始菜单上进行卸载。无论如何,右键单击已安装的应用程序会导致卸载,甚至可能会抑制您的卸载。

【讨论】:

    【解决方案3】:

    创建以下批处理文件。这将运行卸载程序,当卸载程序完成时,它将删除卸载程序和批处理文件。

    START /WAIT YourUninstaller.exe
    Del YourUninstaller.exe
    Del ThisBatchFile.bat
    

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多