protected static string ProcessCommandString(string command) { if (string.IsNullOrEmpty(command)) { return(null); } return(ProcessStartCommand.TryParse(command, out var temp) ? temp.FileName : null); }
public ServiceEntry(string serviceName, string displayName, string command) { ProgramName = serviceName; EntryLongName = displayName; Command = command; if (ProcessStartCommand.TryParse(command, out var pc)) { CommandFilePath = pc.FileName; } else if (File.Exists(command)) { CommandFilePath = command; } FillInformationFromFile(CommandFilePath); }
public static IEnumerable <TaskEntry> GetTaskStartupEntries() { TaskCollection tasks; try { tasks = TaskService.Instance.RootFolder.Tasks; } catch { yield break; } foreach (var task in tasks) { XNamespace xmlNamespace; XElement actionRoot; try { var rootElement = XDocument.Parse(task.Xml).Root; xmlNamespace = rootElement?.Name.Namespace ?? XNamespace.None; actionRoot = rootElement?.Element(xmlNamespace + "Actions"); } catch { continue; } if (actionRoot == null || actionRoot.IsEmpty || xmlNamespace == XNamespace.None) { continue; } foreach (var actionElement in actionRoot.Elements()) { var command = actionElement.Element(xmlNamespace + "Command"); if (string.IsNullOrEmpty(command?.Value)) { continue; } var arguments = actionElement.Element(xmlNamespace + "Arguments"); var cmdCommand = new ProcessStartCommand(command.Value, arguments?.Value ?? string.Empty); yield return(new TaskEntry(task.Name, cmdCommand.ToCommandLine(), cmdCommand.FileName, task)); } } }
public IList <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback) { var results = new List <ApplicationUninstallerEntry>(); if (!ChocoIsAvailable) { return(results); } var result = StartProcessAndReadOutput(ChocoFullFilename, @"list -lo -nocolor --detail"); if (string.IsNullOrEmpty(result)) { return(results); } var re = new System.Text.RegularExpressions.Regex(@"\n\w.+\r\n Title:"); var match = re.Match(result); if (!match.Success) { return(results); } var begin = match.Index + 1; while (true) { match = match.NextMatch(); if (!match.Success) { break; } var end = match.Index + 1; var info = result.Substring(begin, end - begin); int i = info.IndexOf(' '), j = info.IndexOf("\r\n"); var appName = new { name = info.Substring(0, i), version = info.Substring(i + 1, j - i - 1) }; var kvps = ExtractPackageInformation(info); if (kvps.Count == 0) { continue; } var entry = new ApplicationUninstallerEntry(); AddInfo(entry, kvps, "Title", (e, s) => e.RawDisplayName = s); entry.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(appName.version); entry.RatingId = "Choco " + appName.name; entry.UninstallerKind = UninstallerType.Chocolatey; AddInfo(entry, kvps, "Summary", (e, s) => e.Comment = s); if (string.IsNullOrEmpty(entry.Comment)) { AddInfo(entry, kvps, "Description", (e, s) => e.Comment = s); if (string.IsNullOrEmpty(entry.Comment)) { AddInfo(entry, kvps, "Tags", (e, s) => e.Comment = s); } } AddInfo(entry, kvps, "Documentation", (e, s) => e.AboutUrl = s); if (string.IsNullOrEmpty(entry.AboutUrl)) { AddInfo(entry, kvps, "Software Site", (e, s) => e.AboutUrl = s); if (string.IsNullOrEmpty(entry.AboutUrl)) { AddInfo(entry, kvps, "Chocolatey Package Source", (e, s) => e.AboutUrl = s); } } var psc = new ProcessStartCommand(ChocoFullFilename, $"uninstall {appName.name} -y -r"); entry.UninstallString = psc.ToString(); if (entry.RawDisplayName == "Chocolatey") { entry.InstallLocation = GetChocoInstallLocation(); } // Prevent chocolatey from trying to run the original uninstaller (it's deleted by now), only remove the package psc.Arguments += " -n --skipautouninstaller"; var junk = new Junk.Containers.RunProcessJunk(entry, null, psc, Localisation.ChocolateyFactory_UninstallInChocolateyJunkName); junk.Confidence.Add(Junk.Confidence.ConfidenceRecords.ExplicitConnection); junk.Confidence.Add(4); entry.AdditionalJunk.Add(junk); results.Add(entry); begin = end; } return(results); }
public RunProcessJunk(ApplicationUninstallerEntry application, IJunkCreator source, ProcessStartCommand processToStart, string junkName) : base(application, source) { _junkName = junkName; ProcessToStart = processToStart; }
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); }
public IEnumerable <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback) { if (!ChocoIsAvailable) { yield break; } var result = StartProcessAndReadOutput(ChocoLocation, @"list -l -nocolor -y -r"); if (string.IsNullOrEmpty(result)) { yield break; } var appEntries = result.Split(NewlineSeparators, StringSplitOptions.RemoveEmptyEntries); var appNames = appEntries.Select(x => { var i = x.IndexOf('|'); if (i <= 0) { return(null); } return(new { name = x.Substring(0, i), version = x.Substring(i + 1) }); }).Where(x => x != null); foreach (var appName in appNames) { var info = StartProcessAndReadOutput(ChocoLocation, "info -l -nocolor -y -v " + appName.name); var kvps = ExtractPackageInformation(info); if (kvps.Count == 0) { continue; } var entry = new ApplicationUninstallerEntry(); AddInfo(entry, kvps, "Title", (e, s) => e.RawDisplayName = s); entry.DisplayVersion = appName.version; entry.RatingId = "Choco " + appName.name; entry.UninstallerKind = UninstallerType.Chocolatey; AddInfo(entry, kvps, "Summary", (e, s) => e.Comment = s); if (string.IsNullOrEmpty(entry.Comment)) { AddInfo(entry, kvps, "Description", (e, s) => e.Comment = s); if (string.IsNullOrEmpty(entry.Comment)) { AddInfo(entry, kvps, "Tags", (e, s) => e.Comment = s); } } AddInfo(entry, kvps, "Documentation", (e, s) => e.AboutUrl = s); if (string.IsNullOrEmpty(entry.AboutUrl)) { AddInfo(entry, kvps, "Software Site", (e, s) => e.AboutUrl = s); if (string.IsNullOrEmpty(entry.AboutUrl)) { AddInfo(entry, kvps, "Chocolatey Package Source", (e, s) => e.AboutUrl = s); } } var psc = new ProcessStartCommand(ChocoLocation, $"uninstall {appName.name} -y -r"); entry.UninstallString = psc.ToString(); // Prevent chocolatey from trying to run the original uninstaller (it's deleted by now), only remove the package psc.Arguments += " -n --skipautouninstaller"; var junk = new Junk.Containers.RunProcessJunk(entry, null, psc, Localisation.ChocolateyFactory_UninstallInChocolateyJunkName); junk.Confidence.Add(Junk.Confidence.ConfidenceRecords.ExplicitConnection); entry.AdditionalJunk.Add(junk); yield return(entry); } }