El TecnoBaúl de Kiquenet

Kiquenet boring stories

Setup Projects y scripts “uninstall”

Posted by kiquenet en 17 agosto 2012

If the user wants to uninstall the product, he can go to "Add/Remove Programs", or he can just double-click the uninstall.cmd. The contents are:

%windir%\system32\msiexec /x {CC3EB7BF-DD82-48B9-8EC5-1B0B62B6D285}

The GUID there is the ProductCode from the Setup Project in Visual Studio.


How can I dynamically generate a batch file that contains the ProductCode for the, at build time?

"Using Visual Studio 2005/2008, you don’t need to write any code to add a uninstall option for a Setup project (Yes I know some people can write code to do it)

1) In the Setup Project –> File System windows –> Right Click “File System on Target machine” –> add a Special Folder, select System Folder;

2) Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it. Override default properties of this file as follows:

Condition:=Not Installed (make sure you put ‘Not Installed’ exactly like that, same case and everything), Permanent:=True, System:=True, Transitive:=True, Vital:=False.

3) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].

4) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.

The ‘Not Installed’ condition and Permananet:=True ensure that the msiexec.exe is only placed into the system folder as part of the install IF it doesn’t aready exist, and it is not removed on an uninstall – therefore it;s pretty safe to ignore that warning and just go for it.


Otra opciones más enrevesadas:

1.) make your application read command line arguments, the code below is from a WPF project

public partial class App : Application


  void Application_Startup(object sender,StartupEventArgs e)


    for(int i = 0;i != e.Args.Length;++i)


      if(e.Args[i].Split(‘=’)[0].ToLower() == "/u")


        string guid = e.Args[i].Split(‘=’)[1];

        string path = Environment.GetFolderPath(Environment.SpecialFolder.System);

        ProcessStartInfo uninstallProcess = new ProcessStartInfo(path+"\\msiexec.exe","/x "+guid);







To add the uninstall link in the deployment project you just need to follow the steps below:

  1. Select your deployment project and go to the file system editor.
  2. Using the file system editor you navigate to the desired location of the install file.
  3. From the decired location you create a new shortcut to your primary output and name it Uninstall – or whatever else you would like.
  4. In the properties of the new shortcut you set the arguments property to /u=[ProductCode]

2.) creates an uninstall.cmd. It runs as a custom action during installation.

var fso, ts;
var ForWriting= 2;
fso = new ActiveXObject("Scripting.FileSystemObject");

var parameters = Session.Property("CustomActionData").split("|"); 
var targetDir = parameters[0];
var productCode = parameters[1];

ts = fso.OpenTextFile(targetDir + "uninstall.cmd", ForWriting, true);

ts.WriteLine("@echo off");
ts.WriteLine("goto START");
ts.WriteLine(" Uninstall.cmd");
ts.WriteLine("@REM The uuid is the 'ProductCode' in the Visual Studio setup project");
ts.WriteLine("%windir%\\system32\\msiexec /x " + productCode);

Una buena referencia para Extending VS Setup Projects:


Gran referencia que explica en detalle los Setup Projects: PackageCode, ProductCode, UpgradeCode, herramienta Orca, etc.








Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: