问题
I have created an installer for MyProgram using the Visual Studio Installer (Visual Studio Setup Project). It is called "MyProgram Setup.msi". It installs the program fine and if it is uninstalled using the Add/Remove Programs control panel then everything gets removed as it should.
The problem is that I want to add a shortcut to the "User's Programs Menu" under the program shortcut called "Uninstall MyProgram". I have tried doing this in 3 different ways and in all 3 ways if MyProgram is uninstalled using that shortcut, the uninstall will leave behind 2 empty folders ("...Program Files\MyCompany\" and "...Program Files\MyCompany\MyProgram\").
Here are the 3 ways that I have tried to make an uninstaller shortcut:
1) A shortcut to a batch or script file
Uninstall MyProgram.bat:
@ECHO OFF
msiexec /uninstall {MyGUID}
Uninstall MyProgram.vbs:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("START /B msiexec /uninstall {MyGUID}")
Set objShell = Nothing
2) Editing the MSI file using Orca.exe
I found out how to do this using this guide: http://www.codeproject.com/KB/install/MSIShortcuts.aspx
I added the Shortcut Entry to the Shortcut table. Uninstalling worked but it still left behind the 2 empty folders when using this shortcut.
3) From code within MyProgram.exe
I modified MyProgram.exe to take a "/uninstall" command line parameter to run "msiexec.exe /uninstall {MyGUID}" and exit itself. Similar to this solution: http://www.codeproject.com/KB/install/DeployUninstall.aspx
None of these attempts created a shortcut which can uninstall the program as well as the program's base folders. I don't want to switch to some other installer product such as Inno Setup, NSIS, or WiX.
回答1:
If for whatever reason manually running msiexec /x {MyGUID}
doesn't remove all folders, then it's an issue with your setup or something you're doing in your application.
For more information about creating an uninstall shortcut with WiX, check out this blog post which goes into quite a bit of detail. Based on the information shown in the blog post you should be able to work out how to stick with your existing technology and use some variation on the (2) method you mention.
回答2:
It seems that this is a bug in the Visual Studio Installer. I have decided to use WiX instead. It is able to create the uninstall shortcut with correct functionality.
来源:https://stackoverflow.com/questions/2940529/i-have-made-an-installer-for-myprogram-but-the-uninstall-shortcut-that-it-create