Reputation: 177
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 ?
Upvotes: 3
Views: 328
Reputation: 11963
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.
Upvotes: 2
Reputation: 20790
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.
Upvotes: 2
Reputation: 353
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
Upvotes: 0