public static int UninstallUsingMsi(this ApplicationUninstallerEntry entry, MsiUninstallModes mode, bool simulate) { try { var uninstallPath = GetMsiString(entry.BundleProviderKey, mode); if (string.IsNullOrEmpty(uninstallPath)) { return(-1); } var startInfo = ProcessTools.SeparateArgsFromCommand(uninstallPath).ToProcessStartInfo(); startInfo.UseShellExecute = false; if (simulate) { Thread.Sleep(SimulationDelay); return(0); } return(startInfo.StartAndWait()); } catch (IOException) { throw; } catch (InvalidOperationException) { throw; } catch (Exception ex) { throw new FormatException(ex.Message, ex); } }
public void UninstallUsingMsi(MsiUninstallModes mode, IEnumerable <ApplicationUninstallerEntry> selectedUninstallers) { if (!TryGetUninstallLock()) { return; } var listRefreshNeeded = false; try { _lockApplication(true); var results = selectedUninstallers.Take(2).ToList(); if (results.Count != 1) { MessageBoxes.CanSelectOnlyOneItemInfo(); return; } var selected = results.First(); if (!_settings.AdvancedDisableProtection && selected.IsProtected) { MessageBoxes.ProtectedItemError(selected.DisplayName); return; } if (selected.BundleProviderKey.IsEmpty()) { MessageBoxes.UninstallMsiGuidMissing(); return; } if (!CheckForRunningProcessesBeforeUninstall(new[] { selected }, true)) { return; } try { selected.UninstallUsingMsi(mode, _settings.AdvancedSimulate); listRefreshNeeded = true; } catch (Exception ex) { PremadeDialogs.GenericError(ex); } } finally { ReleaseUninstallLock(); _lockApplication(false); if (listRefreshNeeded) { _initiateListRefresh(); } } }
internal static string GetMsiString(Guid bundleProviderKey, MsiUninstallModes mode) { if (bundleProviderKey == Guid.Empty) { return(string.Empty); } switch (mode) { case MsiUninstallModes.InstallModify: return($@"MsiExec.exe /I{bundleProviderKey:B}"); case MsiUninstallModes.QuietUninstall: return($@"MsiExec.exe /qb /X{bundleProviderKey:B} REBOOT=ReallySuppress /norestart"); case MsiUninstallModes.Uninstall: return($@"MsiExec.exe /X{bundleProviderKey:B}"); default: throw new ArgumentOutOfRangeException(nameof(mode), mode, @"Unknown mode"); } }