internal static bool CheckForRunningProcesses(string[] filters, bool doNotKillSteam, Form parentForm = null) { var idsToCheck = GetRelatedProcessIds(filters, doNotKillSteam); if (idsToCheck.Length > 0) { if (!ProcessWaiter.ShowDialog(parentForm ?? MessageBoxes.DefaultOwner, idsToCheck.ToArray(), false)) { return(false); } } return(true); }
internal static bool CheckForRunningProcesses(string[] filters, bool doNotKillSteam, Form parentForm = null) { var myId = Process.GetCurrentProcess().Id; var idsToCheck = new List <int>(); foreach (var pr in Process.GetProcesses()) { try { if (pr.Id == myId) { continue; } if (doNotKillSteam && pr.ProcessName.Equals("steam", StringComparison.InvariantCultureIgnoreCase)) { continue; } if (string.IsNullOrEmpty(pr.MainModule.FileName) || pr.MainModule.FileName.StartsWith(WindowsTools.GetEnvironmentPath(CSIDL.CSIDL_SYSTEM), StringComparison.InvariantCultureIgnoreCase)) { continue; } var filenames = pr.Modules.Cast <ProcessModule>() .Select(x => x.FileName) .Where(s => !string.IsNullOrEmpty(s)) .Distinct(); if (filenames.Any(filename => filters.Any(filter => { if (string.IsNullOrEmpty(filename)) { return(false); } if (!Path.IsPathRooted(filename)) { return(false); } return(filename.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase)); }))) { idsToCheck.Add(pr.Id); } } catch { // Ignore invalid processes } } if (idsToCheck.Count > 0) { if (!ProcessWaiter.ShowDialog(parentForm ?? MessageBoxes.DefaultOwner, idsToCheck.ToArray(), false)) { return(false); } } return(true); }