wix uninstaller(exe)如何自行删除

时间:2018-05-02 14:42:00

标签: c# wix windows-installer uninstall msiexec

我有自定义安装程序和卸载程序,它将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或原始文件)?

3 个答案:

答案 0 :(得分:2)

您可以批量执行此操作!

类似

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

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

答案 1 :(得分:1)

有记录的&#34;如何&#34;对于这种不需要您拥有可执行文件的方案,使用msiexec.exe而不是您自己的可执行文件:

How To: Create an Uninstall Shortcut

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

一般情况下,从Windows 10开始,您不需要在开始菜单上卸载。右键单击已安装的应用程序无论如何都会导致卸载,甚至可能会压制您的。

答案 2 :(得分:0)

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

START /WAIT YourUninstaller.exe
Del YourUninstaller.exe
Del ThisBatchFile.bat
相关问题