[英]How wix uninstaller(exe) can remove itself
I have mine custom installer and uninstaller, which install MSI and other resources to PC. 我有自定义安装程序和卸载程序,它将MSI和其他资源安装到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). 在Uninstaller.exe中,我将自身复制到TEMP文件夹并从那里运行,但问题是我的卸载程序在那里(在TEMP中)。
Question: How I can remove my executable file(from TEMP or original) with wix scripts ? 问题:如何使用wix脚本删除我的可执行文件(来自TEMP或原始文件)?
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. 这将生成一个新的cmd进程,并在10秒后执行delete命令。
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: 有一个文档的“如何”这个场景不需要你有一个可执行文件,使用msiexec.exe而不是你自己的可执行文件:
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). 你没有说你的exe是否做了除了调用卸载之外的任何事情,但IMO完全可以复制到临时文件夹并将可执行文件保留在那里(并且它不需要是exe,因为你可以在其上调用CreateProcess作为.tmp文件)。 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. 通常,从Windows 10开始,您不需要在开始菜单上卸载。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.