/// <summary> /// Attempt to uninstall all the installed msi's /// </summary> /// <remarks> /// TODO: implement ignore_return_code option /// </remarks> public static void UninstallAllInstalledProducts() { foreach (string sourceFile in MSIExec.InstalledMSI) { // This is a best effort attempt to clean up the machine after a test run. // The loop will attempt to uninstall all the msi files registered to be installed. try { string logFile = string.Empty; MSIExecReturnCode exitCode = MSIExec.RunMSIExec(sourceFile, MSIExecMode.Uninstall, null, MSIExecReturnCode.SUCCESS, out logFile); if (MSIExecReturnCode.SUCCESS != exitCode) { Console.WriteLine(string.Format("Failed to uninstall msi '{0}'. Exit code: '{1}'", sourceFile, exitCode.ToString())); } } catch (Exception ex) { Console.WriteLine(string.Format("Failed to uninstall msi '{0}'. Exception raised: '{1}'", sourceFile, ex.Message)); } } MSIExec.InstalledMSI.Clear(); }