Vra

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"?

Was dit nuttig?

Oplossing

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.

Ander wenke

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).

Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top