Click here to Skip to main content
15,897,187 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.2K   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

 
GeneralRe: Nice but... Pin
mjmeans23-Aug-05 12:24
mjmeans23-Aug-05 12:24 
GeneralRe: Nice but... Pin
DanNeely23-Aug-05 15:41
sussDanNeely23-Aug-05 15:41 
GeneralRe: Nice but... Pin
mcarbenay23-Aug-05 22:40
mcarbenay23-Aug-05 22:40 
GeneralRe: Nice but... Pin
mjmeans24-Aug-05 20:55
mjmeans24-Aug-05 20:55 
GeneralRe: Nice but... Pin
mcarbenay24-Aug-05 22:24
mcarbenay24-Aug-05 22:24 
GeneralRe: Nice but... Pin
mjmeans25-Aug-05 8:45
mjmeans25-Aug-05 8:45 
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 
i tried the code (converted to c#) but it got strange reaction.
when i press the uninstall icon the application runs an the uninstall dialog too.
when i press Remove it stuck with error about the application that holds my resources (that i want to uninstall) -
so i need to shutdown the application and press Retry.

isn't there a way to make uninstall without showing the Application in the background?
i tried the code before the "InitializeComponents" and after that before the "Application.Run(new MainForm());" in the static method "Main".

any suggestions or other ways to make uninstall?
Avi.
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 
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.