Click here to Skip to main content
Licence CPOL
First Posted 21 Aug 2005
Views 135,979
Bookmarked 75 times

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

By | 21 Aug 2005 | Article
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().
    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)

About the Author

mjmeans

Systems Engineer
Mark J Means Consulting
United States United States

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWorked but getting an error in some machines PinmemberVaidehi P20:21 16 May '11  
AnswerRe: Worked but getting an error in some machines Pinmembermjmeans11:00 17 May '11  
GeneralVerifying The Link... [modified] Pinmemberjp2code12:04 15 Sep '10  
GeneralCondensed C# Code PinmemberGeo24213:01 27 May '10  
GeneralCode in C# PinmemberNitin Sawant15:53 3 Dec '09  
QuestionWhere should I put these codes? Pinmemberqiux0:51 4 Sep '09  
AnswerRe: Where should I put these codes? Pinmembermjmeans23:01 5 Sep '09  
QuestionHow to Show Product Name while confirming the Unistallation? Pinmemberoops.uvj20:45 19 Aug '09  
AnswerRe: How to Show Product Name while confirming the Unistallation? Pinmembermjmeans7:22 20 Aug '09  
AnswerRe: How to Show Product Name while confirming the Unistallation? Pinmemberstratokazik19:45 17 Aug '10  
GeneralThank you PinmemberSintre11:14 8 Jun '09  
GeneralOne Problem [modified] PinmemberthirstyDev18:43 26 Nov '08  
GeneralRe: One Problem Pinmembermjmeans7:37 27 Nov '08  
GeneralRe: One Problem PinmemberthirstyDev17:46 27 Nov '08  
GeneralEven easier solution PinmemberVyacheslav Trubarov14:28 3 Nov '07  
NewsRe: Even easier solution PinmemberBilal Haider Asi8:46 13 Mar '08  
GeneralNo Code Solution VS2005 Pinmembercode@controlbox.co.uk5:52 9 Aug '07  
GeneralRe: No Code Solution VS2005 Pinmembermjmeans7:26 9 Aug '07  
The license for msiexec does not allow its distribution in this way. i.e. packaged in another installer. Msiexec should only be distributed as part of the Windows Installer 3.1 distribution. Whereas the method you have come up with should work, it is not legal. There is also the possibility that the user has a different version of msiexec already installed in their machine, and this might cause a version conflict.
GeneralRe: No Code Solution VS2005 Pinmembercedear5:50 19 May '08  
GeneralRe: No Code Solution VS2005 Pinmembernnans0:07 29 Oct '08  
GeneralRe: No Code Solution VS2005 Pinmembermjmeans6:16 29 Oct '08  
GeneralRe: No Code Solution VS2005 Pinmembernnans17:07 29 Oct '08  
GeneralRe: No Code Solution VS2005 Pinmembermjmeans2:08 30 Oct '08  
Generala better alternative PinPopularmemberJujiswa12:51 25 Feb '07  
GeneralRe: a better alternative Pinmemberlogan13377:46 28 Jul '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 21 Aug 2005
Article Copyright 2005 by mjmeans
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid