views:

223

answers:

2

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.

A: 

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.

sascha
I have created a clean new program to test out if it is an issue with my setup or program. The program is TestProgram.exe which is a Windows Forms app with no code added to it at all. The Setup is Setup1.msi. The uninstall shortcut leads an Uninstall.bat file which is in the Application folder. You can install and then uninstall using this shortcut without ever running TestProgram.exe. Still, the uninstall shortcut leaves behind 2 empty folders.
Coder7862396
Uninstall.bat is in the package correct? Therefore it is *IN USE* when the uninstall is happening, and so the folders cannot be removed
sascha
Ok, that makes sense. But if I use the #2 method instead and edit the MSI to add a shortcut to msiexec.exe then there is nothing extra in the package or program folder and the only thing in use during uninstall would be msiexec.exe. Even using this way does not solve the problem.
Coder7862396
In that case, I'm stumped.... sorry :(
sascha
A: 

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.

Coder7862396