1

There are two ways to uninstall my application.

  1. By using the same setup.
  2. Add/Remove Programs in Control Panels

We have got a special uninstallation procedure in our setup, and it launches some special dialog boxes to get user inputs. In that way the uninstallation happens according to the user input. But the problem is, that special uninstallation procedure does not execute if you uninstall it by using "Add/Remove Programs". Is there a way to launch the application-specific uninstallation though "Add/Remove Programs"?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ABCD
  • 897
  • 16
  • 38
  • Do you want to launch your customized un-installation dialogs when you click "Uninstall" on Add/Remove programs? – Sandeep Oct 19 '12 at 04:27

2 Answers2

1

If you are using an MSI-based project, then the Uninstall button will run an uninstallation in passive mode. Thus any actions in your UI or dialog sequence will be skipped. To work around this, it's common to disable the uninstall button (see ARPNOREMOVE) and require end users to go through the Modify button (which does show the UI) instead.

Michael Urman
  • 15,737
  • 2
  • 28
  • 44
  • +1, Thanks for your Answer. I have tried to change "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{xxxx}-->UninstallString" in order to get the UI, but failed. Doesn't MsiExce use this string to uninstall the app? If so, what the purpose of UnistallString? – ABCD Oct 29 '12 at 03:42
  • Nope. The UninstallString here is presumably for backwards compatibility with apps that look at the Uninstall key directly but do not know about MSI. See http://stackoverflow.com/a/1826857/89999 – Michael Urman Oct 29 '12 at 12:14
  • What you have proposed is the only possible solution I could find. At the moment we don't provide Modify or Repair options in our setup. But still the ARP button says "Change". Is it possible to change the button display name? – ABCD Nov 02 '12 at 00:44
  • 1
    I believe the text on the button is controlled by Microsoft, so you might be able to see different text by upgrading or downgrading your version of Windows. Otherwise (realistically) you cannot change the text on this button. – Michael Urman Nov 02 '12 at 13:46
0

You can do it using WMI. You can customize your uninstaller software according to your need. For achieving this, you have to use the Win32_Product class and uninstall method. Following is the example of uninstalling a program on the local machine:

using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class CallWMIMethod
    {
        public static void Main()
        {
            try
            {
                ManagementObject classInstance =
                    new ManagementObject("root\\CIMV2",
                    "Win32_Product.IdentifyingNumber='{EDDE41A3-A870-4D97-A1ED-67FF62AA0552}',Name='MyServiceSetup',Version='1.0.0'",
                    null);

                // No method in-parameters to define


                // Execute the method and obtain the return values.
                ManagementBaseObject outParams =
                    classInstance.InvokeMethod("Uninstall", null, null);

                // List outParams
                Console.WriteLine("Out parameters:");
                Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
            }
            catch(ManagementException err)
            {
                MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
            }
        }
    }
}

You can check the return value at Error Codes (Windows Desktop Apps).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61