public void AddMissingInformation(ApplicationUninstallerEntry target) { if (string.IsNullOrEmpty(target.DisplayVersion)) { return; } ApplicationEntryTools.CleanupDisplayVersion(target.DisplayVersion); }
/// <summary> /// Run the uninstaller on a new thread. /// </summary> internal void RunUninstaller(RunUninstallerOptions options) { lock (_operationLock) { if (Finished || IsRunning || CurrentStatus != UninstallStatus.Waiting) { return; } if (UninstallerEntry.IsRegistered && !UninstallerEntry.RegKeyStillExists()) { CurrentStatus = UninstallStatus.Completed; Finished = true; return; } if (UninstallerEntry.UninstallerKind == UninstallerType.Msiexec) { var uninstallString = IsSilentPossible && UninstallerEntry.QuietUninstallPossible ? UninstallerEntry.QuietUninstallString : UninstallerEntry.UninstallString; // Always reenumerate products in case any were uninstalled if (ApplicationEntryTools.PathPointsToMsiExec(uninstallString) && MsiTools.MsiEnumProducts().All(g => !g.Equals(UninstallerEntry.BundleProviderKey))) { CurrentStatus = UninstallStatus.Completed; Finished = true; return; } } CurrentStatus = UninstallStatus.Uninstalling; try { _worker = new Thread(UninstallThread) { Name = "RunBulkUninstall_Worker", IsBackground = false }; _worker.Start(options); } catch { CurrentStatus = UninstallStatus.Failed; Finished = true; throw; } } }
public void AddMissingInformation(ApplicationUninstallerEntry entry) { if (entry.IconBitmap != null) { return; } // Check for any specified icons if (!string.IsNullOrEmpty(entry.DisplayIcon) && !ApplicationEntryTools.PathPointsToMsiExec(entry.DisplayIcon)) { string resultFilename = null; if (File.Exists(entry.DisplayIcon)) { resultFilename = entry.DisplayIcon; } if (resultFilename == null) { try { var fName = ProcessTools.SeparateArgsFromCommand(entry.DisplayIcon).FileName; if (fName != null && File.Exists(fName)) { resultFilename = fName; } } catch { // Ignore error and try another method } } var icon = UninstallToolsGlobalConfig.TryExtractAssociatedIcon(resultFilename); if (icon != null) { entry.DisplayIcon = resultFilename; entry.IconBitmap = icon; } } }
private static IEnumerable <ApplicationUninstallerEntry> GetRelatedUninstallers( ApplicationUninstallerEntry thisUninstaller, IEnumerable <ApplicationUninstallerEntry> other) { return(other.Where(y => ApplicationEntryTools.AreEntriesRelated(thisUninstaller, y, -3))); }
public static UninstallerType GetUninstallerType(string uninstallString) { // Detect MSI / Windows installer based on the uninstall string // e.g. "C:\ProgramData\Package Cache\{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}\vcredist_x86.exe" /uninstall if (ApplicationEntryTools.PathPointsToMsiExec(uninstallString) || uninstallString.ContainsAll( new[] { @"\Package Cache\{", @"}\", ".exe" }, StringComparison.OrdinalIgnoreCase)) { return(UninstallerType.Msiexec); } // Detect Sdbinst if (uninstallString.Contains("sdbinst", StringComparison.OrdinalIgnoreCase) && uninstallString.Contains(".sdb", StringComparison.OrdinalIgnoreCase)) { return(UninstallerType.SdbInst); } if (uninstallString.Contains(@"InstallShield Installation Information\{", StringComparison.OrdinalIgnoreCase)) { return(UninstallerType.InstallShield); } if (uninstallString.Contains("powershell.exe", StringComparison.OrdinalIgnoreCase) || uninstallString.Contains(".ps1", StringComparison.OrdinalIgnoreCase)) { return(UninstallerType.PowerShell); } if (ProcessStartCommand.TryParse(uninstallString, out var ps) && Path.IsPathRooted(ps.FileName) && File.Exists(ps.FileName)) { try { var fileName = Path.GetFileNameWithoutExtension(ps.FileName); // Detect Inno Setup if (fileName != null && InnoSetupFilenameRegex.IsMatch(fileName)) { // Check if Inno Setup Uninstall Log exists if (File.Exists(ps.FileName.Substring(0, ps.FileName.Length - 3) + "dat")) { return(UninstallerType.InnoSetup); } } // Detect NSIS Nullsoft.NSIS. Slow, but there's no other way than to scan the file using (var reader = new StreamReader(ps.FileName, Encoding.ASCII)) { string line; while ((line = reader.ReadLine()) != null) { if (line.Contains("Nullsoft", StringComparison.Ordinal)) { return(UninstallerType.Nsis); } } } /* Unused/unnecessary * if (result.Contains("InstallShield")) * return UninstallerType.InstallShield; * if (result.Contains("Inno.Setup") || result.Contains("Inno Setup")) * return UninstallerType.InnoSetup; * if(result.Contains(@"<description>Adobe Systems Incorporated Setup</description>")) * return UninstallerType.AdobeSetup; */ } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } } return(UninstallerType.Unknown); }
/// <summary> /// A valid guid is REQUIRED. It doesn't have to be set on the entry, but should be. /// </summary> private static void ApplyMsiInfo(ApplicationUninstallerEntry entry, Guid guid) { //IMPORTANT: If MsiGetProductInfo returns null it means that the guid is invalid or app is not installed if (MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME) == null) { return; } FillInMissingInfoMsiHelper(() => entry.RawDisplayName, x => entry.RawDisplayName = x, guid, MsiWrapper.INSTALLPROPERTY.INSTALLEDPRODUCTNAME, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME); FillInMissingInfoMsiHelper(() => entry.DisplayVersion, x => entry.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(x), guid, MsiWrapper.INSTALLPROPERTY.VERSIONSTRING, MsiWrapper.INSTALLPROPERTY.VERSION); FillInMissingInfoMsiHelper(() => entry.Publisher, x => entry.Publisher = x, guid, MsiWrapper.INSTALLPROPERTY.PUBLISHER); FillInMissingInfoMsiHelper(() => entry.InstallLocation, x => entry.InstallLocation = x, guid, MsiWrapper.INSTALLPROPERTY.INSTALLLOCATION); FillInMissingInfoMsiHelper(() => entry.InstallSource, x => entry.InstallSource = x, guid, MsiWrapper.INSTALLPROPERTY.INSTALLSOURCE); FillInMissingInfoMsiHelper(() => entry.UninstallerFullFilename, x => entry.UninstallerFullFilename = x, guid, MsiWrapper.INSTALLPROPERTY.LOCALPACKAGE); FillInMissingInfoMsiHelper(() => entry.DisplayIcon, x => entry.DisplayIcon = x, guid, MsiWrapper.INSTALLPROPERTY.PRODUCTICON); FillInMissingInfoMsiHelper(() => entry.AboutUrl, x => entry.AboutUrl = x, guid, MsiWrapper.INSTALLPROPERTY.HELPLINK, MsiWrapper.INSTALLPROPERTY.URLUPDATEINFO, MsiWrapper.INSTALLPROPERTY.URLINFOABOUT); if (!entry.InstallDate.IsDefault()) { return; } var temp = MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.INSTALLDATE); if (!temp.IsNotEmpty()) { return; } try { entry.InstallDate = new DateTime(int.Parse(temp.Substring(0, 4)), int.Parse(temp.Substring(4, 2)), int.Parse(temp.Substring(6, 2))); } catch { // Date had invalid format, default to nothing } }
/// <summary> /// Add information from FileVersionInfo of specified file to the targetEntry /// </summary> /// <param name="targetEntry">Entry to update</param> /// <param name="infoSourceFilename">Binary file to get the information from</param> /// <param name="onlyUnpopulated">Only update unpopulated fields of the targetEntry</param> internal static void FillInformationFromFileAttribs(ApplicationUninstallerEntry targetEntry, string infoSourceFilename, bool onlyUnpopulated) { FileVersionInfo verInfo; try { verInfo = FileVersionInfo.GetVersionInfo(infoSourceFilename); } catch { return; } Func <string, bool> unpopulatedCheck; if (onlyUnpopulated) { unpopulatedCheck = target => string.IsNullOrEmpty(target?.Trim()); } else { unpopulatedCheck = target => true; } var companyName = verInfo.CompanyName?.Trim(); if (unpopulatedCheck(targetEntry.Publisher) && !string.IsNullOrEmpty(companyName)) { targetEntry.Publisher = companyName; } if (unpopulatedCheck(targetEntry.RawDisplayName)) { var productName = StringTools.StripStringFromVersionNumber(verInfo.FileDescription?.Trim()); if (!string.IsNullOrEmpty(productName)) { targetEntry.RawDisplayName = productName; } else { productName = verInfo.ProductName?.Trim(); if (!string.IsNullOrEmpty(productName)) { targetEntry.RawDisplayName = productName; } } } var comment = verInfo.Comments?.Trim(); if (unpopulatedCheck(targetEntry.Comment) && !string.IsNullOrEmpty(comment)) { targetEntry.Comment = comment; } if (unpopulatedCheck(targetEntry.DisplayVersion)) { var productVersion = verInfo.ProductVersion?.Trim(); if (string.IsNullOrEmpty(productVersion)) { productVersion = verInfo.FileVersion?.Trim(); } if (!string.IsNullOrEmpty(productVersion)) { targetEntry.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(productVersion); } } }