2
votes

I'm using Wix 3.9 and Wix-edit 0.7.5/Notepad++ to create a MSI installer for my application. I want to create an uninstall shortcut inside the installed folder. For instance:

C:\MySoftware\Uninstall.lnk

I tried a few things, but in all cases when I uninstall the software through that link, the program folder C:\MySoftware is not deleted. Uninstalling every other way works as expected.

First I tried to create it as a Component inside the <Directory> tag. Looks to me a bit hacky, because I must add <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>

I also tried replacing <CreateFolder/> with <RemoveFolder Id="MYINSTALLDIR" On="uninstall" />, same results.

Another try:

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

Here, besides having the same results, I get a warning when building: file.wxs(31) : warning LGHT1076 : ICE57: Component 'StartMenuShortcuts' has both per-user and per-machine data with an HKCU Registry KeyPath..

How do I create a shortcut that can be used without affecting the uninstall behavior? I don't know if it makes a difference, but I need this to work without Admin privileges (I'm using <Package ... InstallScope="perUser" InstallPrivileges="limited">).

I know I could just create a .lnk file and add it to the project, but I prefer not to, because then I'd have to worry about updating its GUID on every project.

1
Check if actions RemoveShortcuts and RemoveRegistryValues are scheduled before RemoveFolders. You can do this using Orca.Marlos
In Orca, the "InstallExecuteSequence" entry has a few actions and then: "RemoveRegistryValues", "RemoveShortcuts" and "RemoveFiles" in sequence. Could it be the case that when I uninstall via shortcut, Windows holds that ".lnk" file open? Because when I uninstall via Start Menu link or Control Panel I don't see this behavior.Marcos Dimitrio
Your assumption does make sense. I will investigate if the same occurs in my computer.Marlos

1 Answers

4
votes

The problem occurs because you didn't set the working directory for the msiexec and then it will use the current directory, raising error 2911 (Could not remove the folder).

Add the reference to WindowsFolder:

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

And then modify your shortcut adding the attribute WorkingDirectory="WindowsFolder":

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