Add an uninstall shortcut to setup project

29/06/2008

5 comments

Add an uninstall shortcut to setup project

1. Create simple project UninstallApp.
2.

Main()
{
    string[] arguments = Environment.GetCommandLineArgs();
    foreach(string argument in arguments)
    {
        string[] parameters = argument.Split('=');
        if (parameters[0].ToLower() == "/u")
        {
            string productCode = parameters[1];
            string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
            Process proc = new Process();
            proc.StartInfo.FileName = string.Concat(path,"\\msiexec.exe");
            proc.StartInfo.Arguments = string.Concat(" /i ", productCode);
            proc.Start();
        }
    }

3. Create new setup project
4. Add UninstallApp.exe to “Application Folder” in ‘File System’ part
5. In “User’s Program menu” create shortcut to UninstallApp.exe and in properties of this shortcut in parameter ‘arguments’ insert value “/u=[ProductCode]“.
6.Rebuild deployment project.

Add comment
facebook linkedin twitter email

Leave a Reply

5 comments

  1. Jos14/07/2008 ב 15:32

    With the code above, will the UninstallApp program also remove itself?

    Usually, programs can not remove themselves while running.

    Jos

  2. Jaime peixe13/01/2010 ב 01:56

    Thanks.It’s a great POST!