简体   繁体   中英

How wix uninstaller(exe) can remove itself

I have mine custom installer and uninstaller, which install MSI and other resources to PC. Uninstall process works within the lines below:

<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>  

In Uninstaller.exe i copy itself to TEMP folder and run it from there, but problem is my uninstaller left there (in TEMP).

Question: How I can remove my executable file(from TEMP or original) with wix scripts ?

You can do this with batch!

something like

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

You run it at the uninstaller closing event. This will spawn a new cmd process and execute the delete command after 10seconds.

There is a documented "how to" for this scenario that doesn't require you to have an executable, using msiexec.exe instead of you own executable:

How To: Create an Uninstall Shortcut

You don't say whether your exe does anything other than call the uninstall, but IMO it's perfectly acceptable to copy to a temp folder and leave the executable there (and it doesn't need to be an exe because you can call CreateProcess on it as a .tmp file). There are standard tools that clear out temp folders (Disk Cleanup, server scripts) so don't worry about it.

In general you don't need an uninstall on the start menu from Windows 10 onwards. A right-click on an installed app brings up an uninstall anyway, and it may even suppress yours.

Create following batch file. This will run uninstaller, when uninstaller is done, it will delete uninstaller and batch file both.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM