Add an uninstall start menu item to your .NET deployment project
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.
- Select your deployment project and go to the file system editor, user programs menu.
- Add an additional shortcut to your primary output project and name it Uninstall Application.
- Set the Arguments property to /u=[ProductCode].
- Add the following code to your project's
Main()
sub or startup form'sNew()
sub just before the call toInitializeComponent()
.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 ".