Click here to Skip to main content
15,886,788 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 264.7K   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

 
GeneralDot Net Deployment Pin
chudapji12-Jan-06 18:24
chudapji12-Jan-06 18:24 
GeneralRe: Dot Net Deployment Pin
Subomania28-Jun-06 0:49
Subomania28-Jun-06 0:49 
GeneralAnother argument to Msiexec.exe Pin
dapoussin2-Jan-06 2:55
dapoussin2-Jan-06 2:55 
Generaldon't work in web Pin
VictorVele27-Aug-05 11:11
VictorVele27-Aug-05 11:11 
GeneralNice but... Pin
Dan Neely23-Aug-05 5:47
Dan Neely23-Aug-05 5:47 
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 
That's what I was just going to say ! The very first thought I had, even before I'd finished to read the title : "Isn't it against the Designed For XP logo ?" Smile | :)

Michael CARBENAY
Creo Ignem
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 
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.