如何卸载程序而不重新启动

Lan*_*ond 3 c#

我编写了一个程序,使用C#中的ManagementObject自动卸载许多程序.它工作正常,除了一些程序自动重启计算机,这违背了我的程序的目的.有什么方法可以让它等到一切都完成卸载重启?

以下是实际卸载程序的方法:

static void UninstallProduct(string path)
{
  ManagementObject product = new ManagementObject(path);

  if ((product != null) && (product.Path.ClassName == "Win32_Product"))
  {
    Console.WriteLine(
      "Uninstalling: "
      + product.GetPropertyValue("Name")
      + "...");

    object result = product.InvokeMethod("Uninstall", null);
    Console.WriteLine(
      "The Uninstall method result is {0}",
      result.ToString());
  }
}
Run Code Online (Sandbox Code Playgroud)

Ben*_*igt 5

尝试使用REMOVE=ALLREBOOT=ReallySuppress选项调用MSI(安装程序包).

如果产品使用自定义安装程序而不是使用MSI,则可能没有跳过重新启动的选项.在这种情况下,我会联系开发商,并指出重新启动未经管理员同意的计算机可能构成服务拒绝攻击:干扰与计算设备和故意妨碍或延迟电子通讯,这是州和联邦罪行的操作.如果你"帮助他们避免责任"而不是用法律和起诉威胁击败他们,你可能会得到所需的行为改变(至少在未来的版本中).