/// <summary> /// Given the product name, find it in the product database and silently remove it /// </summary> internal void RemoveOldVersion() { Exception exception = null; string productId = null; EventLogger.WriteInformationalMessage("Attempting to find product: \"{0}\"", _productName); try { productId = FindInstalledProductKey(_productName).ToString("B", CultureInfo.InvariantCulture); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { exception = e; } #pragma warning restore CA1031 // Do not catch general exception types if (exception != null) { EventLogger.WriteWarningMessage("Unable to locate product {0}! Continuing without uninstall", _productName); return; } Stopwatch stopwatch = Stopwatch.StartNew(); Installer.SetInternalUI(InstallUIOptions.Silent); Installer.ConfigureProduct(productId, 0, InstallState.Absent, ""); stopwatch.Stop(); EventLogger.WriteInformationalMessage("Removed productId: {0} in {1} milliseconds", productId, stopwatch.ElapsedMilliseconds); }
static void Main(string[] args) { // Update this name to search for your product. This sample searches for "Orca" var productcode = FindProductCode("orca"); try { if (String.IsNullOrEmpty(productcode)) { throw new ArgumentNullException("productcode"); } // Note: Setting InstallUIOptions to silent will fail uninstall if uninstall requires elevation since UAC prompt then does not show up Installer.SetInternalUI(InstallUIOptions.Full); // Set MSI GUI level (run this function elevated for silent mode) Installer.ConfigureProduct(productcode, 0, InstallState.Absent, "REBOOT=\"ReallySuppress\""); // Check: Installer.RebootInitiated and Installer.RebootRequired; } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } Console.ReadLine(); // Keep console open }
/// <summary> /// Installs a product given the provided <paramref name="data"/>. /// </summary> /// <param name="data">An <see cref="InstallProductActionData"/> with information about the package to install.</param> protected override void ExecuteAction(InstallProductActionData data) { if (!string.IsNullOrEmpty(data.TargetDirectory)) { data.CommandLine += string.Format(CultureInfo.InvariantCulture, @" TARGETDIR=""{0}""", data.TargetDirectory); } if (!string.IsNullOrEmpty(data.Path)) { Installer.InstallProduct(data.Path, data.CommandLine); } else if (!string.IsNullOrEmpty(data.ProductCode)) { Installer.ConfigureProduct(data.ProductCode, INSTALLLEVEL_DEFAULT, InstallState.Default, data.CommandLine); } if (this.PassThru) { var product = ProductInstallation.GetProducts(data.ProductCode, null, UserContexts.All).FirstOrDefault(); if (null != product && product.IsInstalled) { this.WriteObject(product.ToPSObject(this.SessionState.Path)); } } }
public static void UninstallRustLocally() { // NOTE-yacoder-2016-01-17: I used Powershell to find the product code for the new version: // get-wmiobject Win32_Product | where {$_.Name -like "*Rust*"} | Format-Table IdentifyingNumber, Name, LocalPackage // http://stackoverflow.com/questions/29937568/how-can-i-find-the-product-guid-of-an-installed-msi-setup Installer.ConfigureProduct("{4CDA27CB-A984-456D-B418-71B5B64D74C2}", 0, InstallState.Absent, ""); }
public void UninstallMsi(Guid productCode, FileInfo expectedProgramPath) { try { Installer.SetExternalUI( delegate(InstallMessage type, string message, MessageButtons buttons, MessageIcon icon , MessageDefaultButton button) { return(MessageResult.OK); }, InstallLogModes.None); Installer.ConfigureProduct("{" + productCode + "}", 0, InstallState.Absent, ""); this.Log($"Uninstalled package {productCode}."); if (expectedProgramPath != null) { var sw = Stopwatch.StartNew(); while (sw.ElapsedMilliseconds < 1000 * 60) { if (!File.Exists(expectedProgramPath.FullName)) { break; } } } } catch (ArgumentException e) { if (e.Message.Contains("This action is only valid for products that are currently installed.")) { this.Log($"Product {productCode} cannot be uninstalled because it is not installed at the moment."); } } }
public static void Uninstall(string productCode) { Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer"); Installer installer = (Installer)Activator.CreateInstance(type); installer.UILevel = msiUILevelNone; installer.ConfigureProduct(productCode, 0, msiInstallStateAbsent); }
private void Uninstall(InstalledItem item) { UninstallCurrent++; UninstallProgress = UninstallCurrent * 100 / UninstallTotal; Installer.SetInternalUI(InstallUIOptions.ProgressOnly | InstallUIOptions.SourceResolutionOnly | InstallUIOptions.UacOnly); Installer.ConfigureProduct(item.ProductCode, 0, InstallState.Absent, "IGNOREDEPENDENCIES=\"ALL\""); }
/// <summary> /// Uninstalls a product given the provided <paramref name="data"/>. /// </summary> /// <param name="data">An <see cref="InstallProductActionData"/> with information about the package to install.</param> protected override void ExecuteAction(InstallProductActionData data) { data.CommandLine += " REMOVE=ALL"; if (!string.IsNullOrEmpty(data.Path)) { Installer.InstallProduct(data.Path, data.CommandLine); } else if (!string.IsNullOrEmpty(data.ProductCode)) { Installer.ConfigureProduct(data.ProductCode, INSTALLLEVEL_DEFAULT, InstallState.Default, data.CommandLine); } }
public void Cleanup() { var products = ProductInstallation.GetProducts(ExampleProductCode, null, UserContexts.All); if (products.Any(p => p.IsAdvertised || p.IsInstalled)) { var previous = Installer.SetInternalUI(InstallUIOptions.Silent); try { foreach (var product in products) { Installer.ConfigureProduct(product.ProductCode, 0, InstallState.Absent, null); } } finally { Installer.SetInternalUI(previous); } } }
static void Main(string[] args) { var productcode = FindProductCode("orca"); try { if (String.IsNullOrEmpty(productcode)) { throw new ArgumentNullException("productcode"); } Installer.SetInternalUI(InstallUIOptions.Full); // Set MSI GUI level Installer.ConfigureProduct(productcode, 0, InstallState.Absent, "REBOOT=\"ReallySuppress\""); // Check: Installer.RebootInitiated and Installer.RebootRequired; } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } Console.ReadLine(); // Keep console open }
/// <summary> /// Repairs a product given the provided <paramref name="data"/>. /// </summary> /// <param name="data">An <see cref="RepairProductActionData"/> with information about the package to install.</param> protected override void ExecuteAction(RepairProductActionData data) { string mode = this.converter.ConvertToString(data.ReinstallMode); data.CommandLine += " REINSTALL=ALL REINSTALLMODE=" + mode; if (!string.IsNullOrEmpty(data.Path)) { Installer.InstallProduct(data.Path, data.CommandLine); } else if (!string.IsNullOrEmpty(data.ProductCode)) { Installer.ConfigureProduct(data.ProductCode, INSTALLLEVEL_DEFAULT, InstallState.Default, data.CommandLine); } if (this.PassThru) { var product = ProductInstallation.GetProducts(data.ProductCode, null, UserContexts.All).FirstOrDefault(); if (null != product && product.IsInstalled) { this.WriteObject(product.ToPSObject(this.SessionState.Path)); } } }
private void btnUninstall_Click(object sender, RoutedEventArgs e) { if (UninstallGrid.SelectedItems.Count > 0) { var selectedUninstall = UninstallGrid.SelectedItems.Cast <ProgsToDeleteClass>(); var selectedToUninstall = new List <ProgsToDeleteClass>(); foreach (ProgsToDeleteClass install in selectedUninstall) { string productcode = guid.Where(x => x.Value == install.Name).FirstOrDefault().Key; if (productcode != null) { if (productcode.Contains("MsiExec.exe")) { try { string guid = getBetween(productcode, "{", "}"); guid = "{" + guid + "}"; Installer.SetInternalUI(InstallUIOptions.Full); Installer.ConfigureProduct(guid, 0, InstallState.Absent, "IGNOREDEPENDENCIES=\"ALL\""); } catch (Exception ss) { string message = ss.ToString(); MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "SecretService"); } } else { try { ProcessStartInfo iInstall = new ProcessStartInfo(); string path = getBetween(productcode, "\\", ".exe"); path = "C:\\" + path + ".exe"; if (productcode.Contains("--uninstall")) { iInstall.Arguments = "--uninstall"; } else if (productcode.Contains("/uninstall")) { iInstall.Arguments = "/uninstall"; } else if (productcode.Contains("/UNINSTALL")) { iInstall.Arguments = "/UNINSTALL"; } iInstall.FileName = path; Process inst = Process.Start(iInstall); inst.WaitForExit(); } catch (Exception ss) { string message = ss.ToString(); MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show(message, "SecretService"); } } } else { MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show("Невозможно удалить приложение. Вероятнее всего это делается через инсталлятор", "SecretService"); return; } } } }
public static void UninstallRustLocally() { Installer.ConfigureProduct("{35295818-DAA6-43A9-997B-11EB194EFB2F}", 0, InstallState.Absent, ""); }
private static void Uninstall(string productCode) { Installer.SetInternalUI(InstallUIOptions.ProgressOnly | InstallUIOptions.SourceResolutionOnly | InstallUIOptions.UacOnly); Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "IGNOREDEPENDENCIES=\"ALL\""); }