public void Handle(UninstallProductCommand message) { var uninstallString = RegistryFind.TryFindUninstallString(message.Product); if (string.IsNullOrWhiteSpace(uninstallString)) { MessageBox.Show($"Could not find the uninstall command for {message.Product}", "Uninstall was not attempted", MessageBoxButton.OK, MessageBoxImage.Information); return; } var exeEnds = uninstallString.IndexOf(".exe", StringComparison.OrdinalIgnoreCase) + 4; if (exeEnds < 5) { MessageBox.Show($"Could not parse the uninstall command for {message.Product}", "Uninstall was not attempted", MessageBoxButton.OK, MessageBoxImage.Information); return; } var exe = uninstallString.Substring(0, exeEnds); var arguments = uninstallString.Remove(0, exeEnds); try { var psi = new ProcessStartInfo(exe, arguments); psi.UseShellExecute = true; Process.Start(psi)?.WaitForExit(); } catch { MessageBox.Show($"Failed to run uninstall command for {message.Product}. Please use Add/Remove programs in Control Panel", "Uninstall was unsuccessful", MessageBoxButton.OK, MessageBoxImage.Error); } ActivateModel <SelectItemsViewModel>(); }
public Version CurrentVersion() { Version version; RegistryFind.TryFindInstalledVersion(Name, out version); return(version); }
public void FindInstalledProducts() { var installedProducts = RegistryFind.FindInstalledProducts().ToList(); Assert.IsNotEmpty(installedProducts); foreach (var product in installedProducts) { Debug.WriteLine($"{product.ProductName} {product.Publisher} {product.Version}"); } }