MsiExec.exe product id uninstall [duplicate]

亡梦爱人 提交于 2019-12-24 18:31:06

问题


As shown in the picture I've retrieved the uninstallstring of an application.

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?


回答1:


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:

  • WIX (remove all previous versions) (uninstall by upgrade code, or product code)
  • Wix: Get Directory from File Path (find correct product by product name string scan)


来源:https://stackoverflow.com/questions/52271051/msiexec-exe-product-id-uninstall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!