如何卸载程序无需重新启动 [英] How to uninstall program without rebooting

查看:132
本文介绍了如何卸载程序无需重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个程序来自动卸载一些方案,使用的ManagementObject在C#。它工作正常,除了有些程序会自动重新启动计算机,并且违背了我的程序的目的。 ?有什么办法,我可以把它等到一切完成卸载重新启动



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

 静态无效UninstallProduct(字符串路径)
{
的ManagementObject产品=新的ManagementObject(路径);

如果((产品= NULL)及!及(product.Path.ClassName ==的Win32_Product))
{
Console.WriteLine(
卸载
+ product.GetPropertyValue(名称)
+...);

对象result = product.InvokeMethod(卸载,NULL);
Console.WriteLine(
的卸载方法的结果是{0},
result.ToString());
}
}


解决方案

尝试调用MSI(安装程序包)与 REMOVE = ALL 重新启动= REALLYSUPPRESS 选项。



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


I have written a program to automatically uninstall a number of programs, using the ManagementObject in C#. It is working properly, except some programs automatically reboot the computer, and that defeats the purpose of my program. Is there any way that I can make it wait until everything is done uninstalling to reboot?

Here is the method that actually uninstalls the programs:

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

解决方案

Try invoking the MSI (installer package) with the REMOVE=ALL and REBOOT=ReallySuppress options.

If the product uses a custom installer instead of using MSI, it may not have an option to skip reboot. In such cases, I would contact the developers and point out that rebooting the computer without the administrator's consent likely constitutes a denial of service attack: interference with operation of computing equipment and willfully obstructing or delaying electronic communications, which are state and federal crimes. If you are "helping them avoid liability" instead of beating them with the law and threat of prosecution, you may get the desired change in behavior (at least in future versions).

这篇关于如何卸载程序无需重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆