0

As shown in the picture I've retrieved the uninstallstring of an application.enter image description here

And this is the code which I'm trying to make that application uninstall.

uninstlString = Convert.ToString(subkey.GetValue("UninstallString"));
if (uninstlString.Contains("MsiExec.exe"))
{
    //Console.WriteLine(uninstlString);
    //Console.ReadLine();
    string args = "/x{" + uninstlString.Split("/".ToCharArray())[1].Split("I{".ToCharArray())[2];
    //string prdctId = uninstlString.Substring(12);
    uninstallProcess.StartInfo.FileName = uninstlString.Split("/".ToCharArray())[0];
    uninstallProcess.StartInfo.Arguments = args;
    uninstallProcess.StartInfo.UseShellExecute = false;
    uninstallProcess.Start();
    uninstallProcess.WaitForExit();
}

But after running this code...it says it the index is out of range... Can someone help me with the code?

JumpingJezza
  • 5,122
  • 10
  • 62
  • 98
BongJae
  • 29
  • 5
  • Please post a [mcve] with what is in your string and where the exception occurs. – nvoigt Sep 11 '18 at 08:16
  • Which line is "index out of range"? Please update your question. – JumpingJezza Sep 11 '18 at 08:33
  • As I said on your previous question, there's *no* guarantee that `msiexec /x` is the right way to uninstall any particular application, even if its stored `UninstallString` starts with `msiexec`. Those uninstall strings are intended to be used **as is**. You're not meant to be pulling them apart and/or changing uninstall options. – Damien_The_Unbeliever Sep 11 '18 at 08:37

1 Answers1

0

Please see my answer in the duplicate question: Uninstalling program.


MSI API: Rather than string manipulation, use the MSI API properly to uninstall using COM automation. I am not sure what your scenario is, we would need to know more about what your goal is. Very often there are alternative ways to do things that make the whole operation less risky.

Uninstall By Product Name: If you know only the name of the product you want to uninstall, then maybe have a look at how you can use the MSI API to uninstall it here: Is there an alternative to GUID when using msiexec to uninstall an application?

Other Ways to Uninstall: There are also a myriad of other ways to uninstall: Uninstalling an MSI file from the command line without using msiexec.


Some Links:

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140