Click here to Skip to main content
15,893,668 members
Articles / Operating Systems / Windows
Article

Add an uninstall start menu item to your .NET deployment project

Rate me:
Please Sign up or sign in to vote.
4.66/5 (26 votes)
21 Aug 2005CPOL 265.1K   77   54
The simple way to add an uninstall menu item to your .NET deployment project

Introduction

It's super easy to add this to your deployment project.

  1. Select your deployment project and go to the file system editor, user programs menu.
  2. Add an additional shortcut to your primary output project and name it Uninstall Application.
  3. Set the Arguments property to /u=[ProductCode].
  4. Add the following code to your project's Main() sub or startup form's New() sub just before the call to InitializeComponent().
    VB
    Dim arguments As String() = Environment.GetCommandLineArgs()
    Dim argument As String
    For Each argument In arguments
        If argument.Split("=")(0).ToLower = "/u" Then
            Dim guid As String = argument.Split("=")(1)
            Dim path As String = _
               Environment.GetFolderPath(Environment.SpecialFolder.System)
            Dim si As New ProcessStartInfo(path & _
                      "\msiexec.exe", "/i " & guid)
            Process.Start(si)
            Close()
            Application.Exit()
            End
        End If
    Next

That's is! The Deployment project will replace [ProductCode] in the Arguments property with the actual installer project's ProductCode GUID value. Your program will see the /u={Actual ProductCode} argument and pass it to msiexec.exe before exiting.

The installer is run in repair/remove mode for your application. The user is allowed to select repair or remove, and continue. If you want the product to remove only, replace the "/i " with "/x ".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer Mark J Means Consulting
United States United States
I have been a software consultant since 1985 working on everything from the Commodore VIC-20 & RadioShack CoCo games to 8051 Embedded USB Microcontrollers to Windows Vista database applications. I have written over a half million lines of code since 2004. Please see my DataConnectionDialog control at http://mjmeans.com/dcd.aspx.

Comments and Discussions

 
AnswerMSDN link here - How do I create an uninstall link on my shortcut? Pin
Buzzle744-Nov-08 14:35
Buzzle744-Nov-08 14:35 
Generalworks but... Pin
JabraJabra21-Aug-05 22:10
JabraJabra21-Aug-05 22:10 
GeneralRe: works but... Pin
mjmeans22-Aug-05 13:04
mjmeans22-Aug-05 13:04 
GeneralRe: works but... Pin
mjmeans22-Aug-05 13:22
mjmeans22-Aug-05 13:22 
GeneralRe: works but... Pin
JabraJabra22-Aug-05 22:35
JabraJabra22-Aug-05 22:35 
GeneralRe: works but... Pin
John Kang23-Aug-05 4:41
John Kang23-Aug-05 4:41 
GeneralRe: works but... Pin
JabraJabra23-Aug-05 21:43
JabraJabra23-Aug-05 21:43 
GeneralRe: works but... Pin
John Kang24-Aug-05 0:09
John Kang24-Aug-05 0:09 
Hi,

It's the only code you need. It works fine with my apps. please make sure you follow the instructions in this article.

1. create a shortcut of Primary output, and move it to User's Programs Menu, and rename it as Uninstall.
2. Select the renamed item (uninstall), in the property window, set Argument to /u=[ProductCode]
3. Add the code I gave to you in the Main().

Once you installed your app, then you can easily uninstall it.

A simple way to debug your code:

In your setup project property window, copy your ProductCode, for my app it is
{1BC5D02E-7390-4923-8114-E468E35D5468}

set your project commandline argument to /u={1BC5D02E-7390-4923-8114-E468E35D5468}

then you can step into the code in Main() and find where the problem is.

Or simply run from command prompt:
msiexec.exe /i {1BC5D02E-7390-4923-8114-E468E35D5468}
to see if it works on your machine.

Good Luck!

John

GeneralRe: works but... Pin
JabraJabra24-Aug-05 0:35
JabraJabra24-Aug-05 0:35 
GeneralRe: works but... Pin
mjmeans24-Aug-05 21:03
mjmeans24-Aug-05 21:03 
GeneralRe: works but... Pin
rrue11-Sep-08 8:27
rrue11-Sep-08 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.