1

有两种方法可以卸载我的应用程序。

  1. 通过使用相同的设置。
  2. 控制面板中添加/删除程序

我们的设置中有一个特殊的卸载程序,它会启动一些特殊的对话框来获取用户输入。以这种方式,根据用户输入进行卸载。但问题是,如果您使用“添加/删除程序”卸载它,则不会执行特殊的卸载过程。有没有办法通过“添加/删除程序”启动特定于应用程序的卸载?

4

2 回答 2

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.

于 2012-10-19T12:16:06.467 回答
0

您可以使用WMI来完成。您可以根据需要自定义卸载程序软件。为此,您必须使用Win32_Product 类卸载方法。以下是在本地机器上卸载程序的示例:

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);
            }
        }
    }
}

您可以在错误代码Windows 桌面应用程序)处查看返回值。

于 2012-10-19T07:17:37.390 回答