Wix Uninstall Shortcut not working

2019-03-04 14:29发布

问题:

I am trying to create an uninstall shortcut for my application and I am using the exact markup from this link:

http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_uninstall_shortcut.html

It creates a shortcut in the application directory under programs menu folder.

The problem is that on clicking the uninstall shortcut, I get the following error message: "This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer Package"

Below is what I have in the.wxs file

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="APPLICATIONROOTDIRECTORY" Name="MyApplication"/>
        </Directory>
        <Directory Id="ProgramMenuFolder">
            <Directory Id="ApplicationProgramsFolder" Name="MyApplication"/>
        </Directory>
    </Directory>

    <DirectoryRef Id="APPLICATIONROOTDIRECTORY">
        <Component Id="myapplication.exe" Guid="xxxxxxxx-1BF3-4394-ABE4-CABB29D6454C">
            <File Id="myapplication.exe" Source="myapplication.exe" KeyPath="yes" Checksum="yes"/>
        </Component>
        <Component Id="documentation.html" Guid="xxxxxxxx-44F3-4E6C-87B9-903CF17EF002">
            <File Id="documentation.html" Source="documentation.html" KeyPath="yes"/>
        </Component>
    </DirectoryRef>

    <DirectoryRef Id="ApplicationProgramsFolder">
        <Component Id="ApplicationShortcut" Guid="xxxxxxxx-F7C4-40D6-930C-3BD78143A0EF">
            <Shortcut Id="ApplicationStartMenuShortcut" 
                 Name="MyApplication" 
               Description="Uninstall Test"
                Target="[#myapplication.exe]"
                      WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
            <!-- Step 1: Add the uninstall shortcut to your installer package -->
            <Shortcut Id="UninstallProduct"             
                      Name="Uninstall My Application"
                      Description="Uninstalls My Application"
                      Target="[System64Folder]msiexec.exe"
                      Arguments="/x xxxxxxxx-1D27-4656-AB3F-41A2047CB6C0"/>
            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\Microsoft\UninstallTest" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
       </Component>
    </DirectoryRef>

    <Feature Id="MainApplication" Title="Main Application" Level="1">
        <ComponentRef Id="myapplication.exe" />
        <ComponentRef Id="documentation.html" />
        <ComponentRef Id="ApplicationShortcut" />   
    </Feature>
</Product>

I am unable to find a solution to this problem yet. Any help would be appreciated. Thanks

回答1:

Putting uninstall shortcuts in the start menu has always been against guidelines - at least since the early 2000s, and with the new start menu tiles introduced in Windows 8 it is very unadvisable indeed to do so. Please read the following article: Desktop App Tiles on the Start Screen (do's and don'ts).

I don't have a system to test on, but Windows 8 may actually hide uninstall shortcuts. You should avoid other shortcuts as well (readme files, website shortcuts, etc...). I just tested on Windows 10 though, and I can indeed see an uninstall shortcut in the start menu.

In this particular case my advise would actually be to eliminate your custom shortcut and declare success that way. Sorry if this isn't ideal for you, but if you don't mind me saying so: don't fight the basic Windows designs - they fight back, and you will always regret trying to tame them. Just saddle up the wild beast and let it rip :-).

With that being said, you may have mismatched the ProductCode in the uninstall shortcut as Chris Painter suggests. For debugging you could try changing: Arguments="/x xxxxxxxx-1D27-4656-AB3F-41A2047CB6C0"/> to Arguments="/x [ProductCode]"/> so it looks like this:

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

Remember to uninstall all instances, rebuild and then install the new version to test all this.

I ran a quick test and this worked on Windows 10. You should still remove that shortcut though in my opinon. Interestingly adding an Internet shortcut in the same location (file was created on disk) was not visible in the start menu (which may indicate shortcut hiding in Windows 10 as well).

For Reference:

  • Shortcuts with name "Uninstall <Program Name>" are not displayed in Windows 8/8.1/10


回答2:

An uninstall will attempt to open and run the InstallExecuteSequence of the cached MSI file, typically [hex string].msi in \Windows\installer so if it cannot find the file:

  1. Verify that the cached MSI is actually there and has not been removed (some people clear the folder).

  2. If you have the original MSI in the location that the package was installed from it may also try to access the MSI from there, so is that package available?

  3. There might be a security issue, so verify that the msiexec process initiated from the shortcut has the privilege to access the cached MSI file. I

If you can successfully uninstall from Programs&Features then I'd suspect that the uninstall process is running with a user account that doesn't have access to the cached MSI file.