WIX - 在已安装的文件夹中创建卸载快捷方式

WIX - Creating an uninstall shortcut inside installed folder

我正在使用 Wix 3.9 和 Wix-edit 0.7.5/Notepad++ 为我的应用程序创建 MSI 安装程序。我想在已安装的文件夹中创建一个卸载快捷方式。例如:

C:\MySoftware\Uninstall.lnk

我尝试了一些方法,但在所有情况下,当我通过 link 卸载软件时,程序文件夹 C:\MySoftware 都没有被删除。卸载所有其他方式都按预期工作。

首先,我尝试将其创建为 <Directory> 标记内的组件。在我看来有点老套,因为我必须添加 <CreateFolder>:

<Directory Id="MYINSTALLDIR" Name="MySoftware">
    <!-- my files... -->

    <Component Id="ABC" Guid="PUT-GUID-HERE">
        <CreateFolder/> <!-- have to add this -->
        <Shortcut Id="UninstallProduct" Name="Uninstall MySoftware" Description="Uninstalls MySoftware" Target="[System64Folder]msiexec.exe" Arguments="/x [ProductCode]"/>
    </Component>

</Directory>

<Feature Id="DefaultFeature" Title="Main Feature" Level="1">
    <!-- some references... -->
    <ComponentRef Id="ABC" />
</Feature>

我也试过用[=17=替换<CreateFolder/>,结果一样。

再试一次:

<DirectoryRef Id="ApplicationProgramsFolder">
    <Component Id="StartMenuShortcuts" Guid="*">
        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" />
        <Shortcut Id="UninstallProduct1" Name="Uninstall MySoftware" Description="Uninstalls MySoftware" Target="[System64Folder]msiexec.exe" Arguments="/x [ProductCode]"/>
        <Shortcut Id="UninstallProduct2" Name="Uninstall MySoftware" Description="Uninstalls MySoftware" Target="[System64Folder]msiexec.exe" Arguments="/x [ProductCode]" Directory="MYINSTALLDIR" />
    </Component>
</DirectoryRef>

在这里,除了有相同的结果外,我在构建时收到警告:file.wxs(31) : warning LGHT1076 : ICE57: Component 'StartMenuShortcuts' has both per-user and per-machine data with an HKCU Registry KeyPath.

如何创建可以在不影响卸载行为的情况下使用的快捷方式?我不知道它是否有所作为,但我需要它在没有管理员权限的情况下工作(我正在使用 <Package ... InstallScope="perUser" InstallPrivileges="limited">)。

我知道我可以创建一个 .lnk 文件并将其添加到项目中,但我不想这样做,因为这样我就不得不担心在每个项目上更新它的 GUID。

出现问题是因为您没有为 msiexec 设置工作目录,然后它将使用当前目录,引发错误 2911(无法删除文件夹)。

添加对 WindowsFolder 的引用:

<Directory Id="MYINSTALLDIR" Name="MySoftware">
    ...
    <Directory Id="WindowsFolder" Name="WindowsFolder" />
</Directory>

然后修改你的快捷方式添加属性WorkingDirectory="WindowsFolder":

<Shortcut Id="UninstallProduct" Name="Uninstall MySoftware" 
          Description="Uninstalls MySoftware" Target="[System64Folder]msiexec.exe"
          Arguments="/x [ProductCode]" WorkingDirectory="WindowsFolder" />