private static bool Prompt(IWin32Window window, int[] pids, string[] names, string action, string content, bool promptOnlyIfDangerous) { if (!Settings.Instance.WarnDangerous) { return(true); } string name = "the selected process(es)"; if (pids.Length == 1) { name = names[0]; } else { name = "the selected processes"; } bool dangerous = false; foreach (int pid in pids) { if (PhUtils.IsDangerousPid(pid)) { dangerous = true; break; } } bool critical = false; foreach (int pid in pids) { try { using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryInformation)) { if (phandle.IsCritical()) { critical = true; break; } } } catch { } } if (promptOnlyIfDangerous && !dangerous && !critical) { return(true); } DialogResult result = DialogResult.No; if (OSVersion.HasTaskDialogs) { TaskDialog td = new TaskDialog(); td.WindowTitle = "Process Hacker"; td.MainInstruction = "Do you want to " + action + " " + name + "?"; td.Content = content; if (critical) { td.MainIcon = TaskDialogIcon.Warning; td.Content = "You are about to " + action + " one or more CRITICAL processes. " + "Windows is designed to break (crash) when one of these processes is terminated. " + "Are you sure you want to continue?"; } else if (dangerous) { td.MainIcon = TaskDialogIcon.Warning; td.Content = "You are about to " + action + " one or more system processes. " + "Doing so will cause system instability. Are you sure you want to continue?"; } if (pids.Length > 1) { td.ExpandFooterArea = true; td.ExpandedInformation = "Processes:\r\n"; for (int i = 0; i < pids.Length; i++) { bool dangerousPid, criticalPid; dangerousPid = PhUtils.IsDangerousPid(pids[i]); try { using (var phandle = new ProcessHandle(pids[i], ProcessAccess.QueryInformation)) criticalPid = phandle.IsCritical(); } catch { criticalPid = false; } td.ExpandedInformation += names[i] + " (PID " + pids[i].ToString() + ")" + (dangerousPid ? " (system process) " : "") + (criticalPid ? " (CRITICAL) " : "") + "\r\n"; } td.ExpandedInformation = td.ExpandedInformation.Trim(); } td.Buttons = new TaskDialogButton[] { new TaskDialogButton((int)DialogResult.Yes, char.ToUpper(action[0]) + action.Substring(1)), new TaskDialogButton((int)DialogResult.No, "Cancel") }; td.DefaultButton = (int)DialogResult.No; result = (DialogResult)td.Show(window); } else { if (critical) { result = MessageBox.Show("You are about to " + action + " one or more CRITICAL processes. " + "Windows is designed to break (crash) when one of these processes is terminated. " + "Are you sure you want to " + action + " " + name + "?", "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } else if (dangerous) { result = MessageBox.Show("You are about to " + action + " one or more system processes. " + "Are you sure you want to " + action + " " + name + "?", "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } else { result = MessageBox.Show("Are you sure you want to " + action + " " + name + "?", "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } } return(result == DialogResult.Yes); }