Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uninstall program without rebooting

Tags:

c#

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());
  }
}
like image 798
Landon Hammond Avatar asked Aug 25 '26 23:08

Landon Hammond


1 Answers

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

like image 69
Ben Voigt Avatar answered Aug 27 '26 14:08

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!