Exemplo n.º 1
0
        private static bool Prompt(IWin32Window window, string name,
            string action, string content)
        {
            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;

                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
            {
                result = MessageBox.Show("Are you sure you want to " + action + " " + name + "?",
                    "Process Hacker", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }

            return result == DialogResult.Yes;
        }
        /// <summary>
        /// TaskDialog wrapped in a CommonDialog class. THis is required to work well in
        /// MMC 2.1. In MMC 2.1 you must use the ShowDialog methods on the MMC classes to
        /// correctly show a modal dialog. This class will allow you to do this and keep access
        /// to the results of the TaskDialog.
        /// </summary>
        /// <param name="taskDialog">The TaskDialog to show.</param>
        public TaskDialogCommonDialog(TaskDialog taskDialog)
        {
            if (taskDialog == null)
            {
                throw new ArgumentNullException("taskDialog");
            }

            this.taskDialog = taskDialog;
        }
Exemplo n.º 3
0
        private static bool Prompt(IWin32Window window, string service, string action, string content, TaskDialogIcon icon)
        {
            DialogResult result = DialogResult.No;

            if (OSVersion.HasTaskDialogs)
            {
                TaskDialog td = new TaskDialog
                {
                    PositionRelativeToWindow = true, 
                    WindowTitle = "Process Hacker", 
                    MainInstruction = "Do you want to " + action + " " + service + "?", 
                    MainIcon = icon, 
                    Content = content, 
                    Buttons = new TaskDialogButton[]
                    {
                        new TaskDialogButton((int)DialogResult.Yes, char.ToUpper(action[0]) + action.Substring(1)),
                        new TaskDialogButton((int)DialogResult.No, "Cancel")
                    }, 
                    DefaultButton = (int)DialogResult.No
                };


                result = (DialogResult)td.Show(window);
            }
            else
            {
                result = MessageBox.Show(
                    "Are you sure you want to " + action + " " + service + "?",
                    "Process Hacker", 
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Exclamation, 
                    MessageBoxDefaultButton.Button2
                    );
            }

            return result == DialogResult.Yes;
        }
        public static void ShowWarning(IWin32Window window, bool force)
        {
            // The message is too clumsy to display with a standard 
            // message box.
            if (!OSVersion.HasTaskDialogs)
                return;

            if (Settings.Instance.DbgHelpWarningShown && !force)
                return;

            try
            {
                var modules = ProcessHandle.Current.GetModules();

                foreach (var module in modules)
                {
                    if (module.FileName.ToLowerInvariant().EndsWith("dbghelp.dll"))
                    {
                        if (!File.Exists(Path.GetDirectoryName(module.FileName) + "\\symsrv.dll"))
                        {
                            if (!force)
                                Settings.Instance.DbgHelpWarningShown = true;

                            TaskDialog td = new TaskDialog();
                            bool verificationChecked;

                            td.CommonButtons = TaskDialogCommonButtons.Ok;
                            td.WindowTitle = "Process Hacker";
                            td.MainIcon = TaskDialogIcon.Warning;
                            td.MainInstruction = "Microsoft Symbol Server not supported";
                            td.Content =
                                "Process Hacker is not configured correctly to obtain debugging symbols. " +
                                "If you do not require proper symbol support, you may ignore this warning.";
                            td.ExpandedByDefault = false;
                            td.ExpandedControlText = "More information";
                            td.ExpandedInformation =
                                "To ensure you have the latest version of dbghelp.dll, download " +
                                "<a href=\"dbghelp\">Debugging " +
                                "Tools for Windows</a> and configure Process Hacker to " +
                                "use its version of dbghelp.dll. If you have the latest version of dbghelp.dll, " +
                                "ensure that symsrv.dll resides in the same directory as dbghelp.dll.";
                            td.EnableHyperlinks = true;
                            td.Callback = (taskDialog, args, callbackData) =>
                            {
                                if (args.Notification == TaskDialogNotification.HyperlinkClicked)
                                {
                                    try
                                    {
                                        System.Diagnostics.Process.Start(
                                            "http://www.microsoft.com/whdc/devtools/debugging/default.mspx");
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("Could not open the hyperlink: " + ex.ToString(),
                                            "Process Hacker", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }

                                    return true;
                                }

                                return false;
                            };
                            td.VerificationText = force ? null : "Do not display this warning again";
                            td.VerificationFlagChecked = true;

                            td.Show(window, out verificationChecked);

                            if (!force)
                                Settings.Instance.DbgHelpWarningShown = verificationChecked;
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex);
            }
        }
Exemplo n.º 5
0
        private void createDumpFileProcessMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Dump Files (*.dmp)|*.dmp|All Files (*.*)|*.*";
            sfd.FileName =
                processP.Dictionary[processSelectedPid].Name +
                "_" +
                DateTime.Now.ToString("yyMMdd") +
                ".dmp";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;

                try
                {
                    Exception exception = null;

                    ThreadStart dumpProcess = () =>
                        {
                            try
                            {
                                using (var phandle = new ProcessHandle(processSelectedPid,
                                    ProcessAccess.DupHandle | ProcessAccess.QueryInformation |
                                    ProcessAccess.SuspendResume | ProcessAccess.VmRead))
                                    phandle.WriteDump(sfd.FileName);
                            }
                            catch (Exception ex2)
                            {
                                exception = ex2;
                            }
                        };

                    if (OSVersion.HasTaskDialogs)
                    {
                        // Use a task dialog to display a fancy progress bar.
                        TaskDialog td = new TaskDialog();
                        Thread t = new Thread(dumpProcess);

                        td.AllowDialogCancellation = false;
                        td.Buttons = new TaskDialogButton[] { new TaskDialogButton((int)DialogResult.OK, "Close") };
                        td.WindowTitle = "Process Hacker";
                        td.MainInstruction = "Creating the dump file...";
                        td.ShowMarqueeProgressBar = true;
                        td.EnableHyperlinks = true;
                        td.CallbackTimer = true;
                        td.Callback = (taskDialog, args, userData) =>
                            {
                                if (args.Notification == TaskDialogNotification.Created)
                                {
                                    taskDialog.SetMarqueeProgressBar(true);
                                    taskDialog.SetProgressBarState(ProgressBarState.Normal);
                                    taskDialog.SetProgressBarMarquee(true, 100);
                                    taskDialog.EnableButton((int)DialogResult.OK, false);
                                }
                                else if (args.Notification == TaskDialogNotification.Timer)
                                {
                                    if (!t.IsAlive)
                                    {
                                        taskDialog.EnableButton((int)DialogResult.OK, true);
                                        taskDialog.SetProgressBarMarquee(false, 0);
                                        taskDialog.SetMarqueeProgressBar(false);

                                        if (exception == null)
                                        {
                                            taskDialog.SetMainInstruction("The dump file has been created.");
                                            taskDialog.SetContent(
                                                "The dump file has been saved at: <a href=\"file\">" + sfd.FileName + "</a>.");
                                        }
                                        else
                                        {
                                            taskDialog.UpdateMainIcon(TaskDialogIcon.Warning);
                                            taskDialog.SetMainInstruction("Unable to create the dump file.");
                                            taskDialog.SetContent(
                                                "The dump file could not be created: " + exception.Message
                                                );
                                        }
                                    }
                                }
                                else if (args.Notification == TaskDialogNotification.HyperlinkClicked)
                                {
                                    if (args.Hyperlink == "file")
                                        Utils.ShowFileInExplorer(sfd.FileName);

                                    return true;
                                }

                                return false;
                            };

                        t.Start();
                        td.Show(this);
                    }
                    else
                    {
                        // No task dialogs, do the thing on the GUI thread.
                        dumpProcess();

                        if (exception != null)
                            PhUtils.ShowException("Unable to create the dump file", exception);
                    }
                }
                catch (Exception ex)
                {
                    PhUtils.ShowException("Unable to create the dump file", ex);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Exemplo n.º 6
0
        private void buttonTerminate_Click(object sender, EventArgs e)
        {
            if (OSVersion.HasTaskDialogs)
            {
                TaskDialog td = new TaskDialog();

                td.WindowTitle = "Process Hacker";
                td.MainIcon = TaskDialogIcon.Warning;
                td.MainInstruction = "Do you want to terminate the job?";
                td.Content = "Terminating a job will terminate all processes assigned to it. Are you sure " +
                    "you want to continue?";
                td.Buttons = new TaskDialogButton[]
                {
                    new TaskDialogButton((int)DialogResult.Yes, "Terminate"),
                    new TaskDialogButton((int)DialogResult.No, "Cancel")
                };
                td.DefaultButton = (int)DialogResult.No;

                if (td.Show(this) == (int)DialogResult.No)
                    return;
            }
            else
            {
                if (MessageBox.Show("Are you sure you want to terminate the job? This action will " +
                    "terminate all processes associated with the job.", "Process Hacker",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                    return;
            }

            try
            {
                using (var jhandle2 = _jobObject.Duplicate(JobObjectAccess.Terminate))
                    JobObjectHandle.FromHandle(jhandle2).Terminate();
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to terminate the job", ex);
            }
        }
Exemplo n.º 7
0
        private static void LoadSettings(bool useSettings, string settingsFileName)
        {
            if (!useSettings)
            {
                Settings.Instance = new Settings(null);
                return;
            }

            if (settingsFileName == null)
            {
                bool success = true;
                string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

                try
                {
                    if (!System.IO.Directory.Exists(appData + @"\Process Hacker"))
                    {
                        System.IO.Directory.CreateDirectory(appData + @"\Process Hacker");
                    }
                }
                catch (Exception ex)
                {
                    PhUtils.ShowException("Unable to create the settings directory", ex);
                    success = false;
                }

                if (success)
                {
                    settingsFileName = appData + @"\Process Hacker\settings.xml";
                }
            }

            // Make sure we have an absolute path so we don't run into problems 
            // when saving.
            if (!string.IsNullOrEmpty(settingsFileName))
            {
                try
                {
                    settingsFileName = System.IO.Path.GetFullPath(settingsFileName);
                }
                catch (Exception ex)
                {
                    PhUtils.ShowException("Unable to parse the settings file name", ex);
                    Environment.Exit(1);
                }
            }

            try
            {
                Settings.Instance = new Settings(settingsFileName);
            }
            catch
            {
                // Settings file is probably corrupt. Ask the user.
                DialogResult result;

                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog
                    {
                        MainIcon = TaskDialogIcon.Warning,
                        PositionRelativeToWindow = true,
                        MainInstruction = "The settings file is corrupt",
                        WindowTitle = "Process Hacker",
                        Content = "The settings file used by Process Hacker is corrupt. You can either " +
                        "delete the settings file or start Process Hacker with default settings.",
                        UseCommandLinks = true,
                        Buttons = new TaskDialogButton[]
                        {
                            new TaskDialogButton((int)DialogResult.Yes, "Delete the settings file\n" + settingsFileName),
                            new TaskDialogButton((int)DialogResult.No, "Start with default settings\nAny settings you change will not be saved."),
                        },
                        CommonButtons = TaskDialogCommonButtons.Cancel
                    };
                    result = (DialogResult)td.Show();
                }
                else
                {
                    result = MessageBox.Show("The settings file used by Process Hacker is corrupt. It will be deleted " + 
                        "and all settings will be reset.", "Process Hacker", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                    if (result == DialogResult.OK)
                        result = DialogResult.Yes;
                    else
                        result = DialogResult.Cancel;
                }

                switch (result)
                {
                    case DialogResult.Yes:
                        {
                            try
                            {
                                System.IO.File.Delete(settingsFileName);
                            }
                            catch (Exception ex)
                            {
                                PhUtils.ShowException("Unable to delete the settings file", ex);
                                Environment.Exit(1);
                            }
                            Settings.Instance = new Settings(settingsFileName);
                            break;
                        }
                    case DialogResult.No:
                        {
                            Settings.Instance = new Settings(null);
                            break;
                        }
                    case DialogResult.Cancel:
                        {
                            Environment.Exit(0);
                        }
                        break;
                }
            }
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        private static ElevationAction PromptForElevation(IWin32Window window, int[] pids, string[] names,
            ProcessAccess access, string elevateAction, string action)
        {
            if (Settings.Instance.ElevationLevel == (int)ElevationLevel.Never)
                return ElevationAction.NotRequired;

            if (
                OSVersion.HasUac &&
                Program.ElevationType == ProcessHacker.Native.Api.TokenElevationType.Limited &&
                KProcessHacker.Instance == null
                )
            {
                try
                {
                    foreach (int pid in pids)
                    {
                        using (var phandle = new ProcessHandle(pid, access))
                        { }
                    }
                }
                catch (WindowsException ex)
                {
                    if (ex.ErrorCode != Win32Error.AccessDenied)
                        return ElevationAction.NotRequired;

                    if (Settings.Instance.ElevationLevel == (int)ElevationLevel.Elevate)
                        return ElevationAction.Elevate;

                    TaskDialog td = new TaskDialog();

                    td.WindowTitle = "Process Hacker";
                    td.MainIcon = TaskDialogIcon.Warning;
                    td.MainInstruction = "Do you want to " + elevateAction + "?";
                    td.Content = "The action cannot be performed in the current security context. " +
                        "Do you want Process Hacker to prompt for the appropriate credentials and " + elevateAction + "?";

                    td.ExpandedInformation = "Error: " + ex.Message + " (0x" + ex.ErrorCode.ToString("x") + ")";
                    td.ExpandFooterArea = true;

                    td.Buttons = new TaskDialogButton[]
                    {
                        new TaskDialogButton((int)DialogResult.Yes, "Elevate\nPrompt for credentials and " + elevateAction + "."),
                        new TaskDialogButton((int)DialogResult.No, "Continue\nAttempt to perform the action without elevation.")
                    };
                    td.CommonButtons = TaskDialogCommonButtons.Cancel;
                    td.UseCommandLinks = true;
                    td.Callback = (taskDialog, args, userData) =>
                    {
                        if (args.Notification == TaskDialogNotification.Created)
                        {
                            taskDialog.SetButtonElevationRequiredState((int)DialogResult.Yes, true);
                        }

                        return false;
                    };

                    DialogResult result = (DialogResult)td.Show(window);

                    if (result == DialogResult.Yes)
                    {
                        return ElevationAction.Elevate;
                    }
                    else if (result == DialogResult.No)
                    {
                        return ElevationAction.DontElevate;
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return ElevationAction.Cancel;
                    }
                }
            }

            return ElevationAction.NotRequired;
        }
Exemplo n.º 10
0
        private static void VerifySettings()
        {
            try
            {
                var a = Properties.Settings.Default.AlwaysOnTop;
            }
            catch (Exception ex)
            {
                Logging.Log(ex);

                try { ThemingScope.Activate(); }
                catch { }

                BadConfig = true;

                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog();

                    td.WindowTitle = "Process Hacker";
                    td.MainInstruction = "Process Hacker could not initialize the configuration manager";
                    td.Content = "The Process Hacker configuration file is corrupt or the configuration manager " +
                        "could not be initialized. Do you want Process Hacker to reset your settings?";
                    td.MainIcon = TaskDialogIcon.Warning;
                    td.CommonButtons = TaskDialogCommonButtons.Cancel;
                    td.Buttons = new TaskDialogButton[]
                    {
                        new TaskDialogButton((int)DialogResult.Yes, "Yes, reset the settings and restart Process Hacker"),
                        new TaskDialogButton((int)DialogResult.No, "No, attempt to start Process Hacker anyway"),
                        new TaskDialogButton((int)DialogResult.Retry, "Show me the error message")
                    };
                    td.UseCommandLinks = true;
                    td.Callback = (taskDialog, args, userData) =>
                    {
                        if (args.Notification == TaskDialogNotification.ButtonClicked)
                        {
                            if (args.ButtonId == (int)DialogResult.Yes)
                            {
                                taskDialog.SetMarqueeProgressBar(true);
                                taskDialog.SetProgressBarMarquee(true, 1000);

                                try
                                {
                                    DeleteSettings();
                                    System.Diagnostics.Process.Start(Application.ExecutablePath);
                                }
                                catch (Exception ex2)
                                {
                                    taskDialog.SetProgressBarMarquee(false, 1000);
                                    PhUtils.ShowException("Unable to reset the settings", ex2);
                                    return true;
                                }

                                return false;
                            }
                            else if (args.ButtonId == (int)DialogResult.Retry)
                            {
                                InformationBox box = new InformationBox(ex.ToString());

                                box.ShowDialog();

                                return true;
                            }
                        }

                        return false;
                    };

                    int result = td.Show();

                    if (result == (int)DialogResult.No)
                    {
                        return;
                    }
                }
                else
                {
                    if (MessageBox.Show("Process Hacker cannot start because your configuration file is corrupt. " +
                        "Do you want Process Hacker to reset your settings?", "Process Hacker", MessageBoxButtons.YesNo,
                        MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        try
                        {
                            DeleteSettings();
                            MessageBox.Show("Process Hacker has reset your settings and will now restart.", "Process Hacker",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            System.Diagnostics.Process.Start(Application.ExecutablePath);
                        }
                        catch (Exception ex2)
                        {
                            Logging.Log(ex2);

                            MessageBox.Show("Process Hacker could not reset your settings. Please delete the folder " +
                                "'wj32' in your Application Data/Local Application Data directories.",
                                "Process Hacker", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }

                Win32.ExitProcess(0);
            }
        }
Exemplo n.º 11
0
        private static void ElevateIfRequired(IWin32Window window, int session, string actionName, Action action)
        {
            if (Properties.Settings.Default.ElevationLevel == (int)ElevationLevel.Never)
                return;

            try
            {
                action();
            }
            catch (WindowsException ex)
            {
                if (ex.ErrorCode == Win32Error.AccessDenied &&
                    OSVersion.HasUac &&
                    Program.ElevationType == ProcessHacker.Native.Api.TokenElevationType.Limited)
                {
                    DialogResult result;

                    if (Properties.Settings.Default.ElevationLevel == (int)ElevationLevel.Elevate)
                    {
                        result = DialogResult.Yes;
                    }
                    else
                    {
                        TaskDialog td = new TaskDialog();

                        td.WindowTitle = "Process Hacker";
                        td.MainIcon = TaskDialogIcon.Warning;
                        td.MainInstruction = "Do you want to elevate the action?";
                        td.Content = "The action could not be performed in the current security context. " +
                            "Do you want Process Hacker to prompt for the appropriate credentials and elevate the action?";

                        td.ExpandedInformation = "Error: " + ex.Message + " (0x" + ex.ErrorCode.ToString("x") + ")";
                        td.ExpandFooterArea = true;

                        td.Buttons = new TaskDialogButton[]
                        {
                            new TaskDialogButton((int)DialogResult.Yes, "Elevate\nPrompt for credentials and elevate the action.")
                        };
                        td.CommonButtons = TaskDialogCommonButtons.Cancel;
                        td.UseCommandLinks = true;
                        td.Callback = (taskDialog, args, userData) =>
                        {
                            if (args.Notification == TaskDialogNotification.Created)
                            {
                                taskDialog.SetButtonElevationRequiredState((int)DialogResult.Yes, true);
                            }

                            return false;
                        };

                        result = (DialogResult)td.Show(window);
                    }

                    if (result == DialogResult.Yes)
                    {
                        Program.StartProcessHackerAdmin("-e -type session -action " + actionName + " -obj \"" +
                            session.ToString() + "\" -hwnd " + window.Handle.ToString(), null, window.Handle);
                    }
                }
                else
                {
                    PhUtils.ShowException("Unable to " + actionName + " the session", ex);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Asks if the user wants to perform an action.
        /// </summary>
        /// <param name="verb">
        /// The action to be performed, e.g. "Terminate"
        /// </param>
        /// <param name="obj">
        /// The object for the action to be performed on, e.g. "the selected process"
        /// </param>
        /// <param name="message">
        /// Additional information to show to the user, e.g. "Terminating a process will ..."
        /// </param>
        /// <param name="warning">Whether the message is a warning.</param>
        /// <returns>Whether the user wants to continue with the operation.</returns>
        public static bool ShowConfirmMessage(string verb, string obj, string message, bool warning)
        {
            // Make the sure the verb is all lowercase.
            verb = verb.ToLower();

            // "terminate" -> "Terminate"
            string verbCaps = char.ToUpper(verb[0]) + verb.Substring(1);
            // "terminate", "the process" -> "terminate the process"
            string action = verb + " " + obj;

            // Example:
            // __________________________________________________
            // | Process Hacker                             _ O x|
            // |                                                 |
            // |    /\     Do you want to terminate the process? |
            // |   /||\                                          |
            // |  /_||_\   Terminating a process may result in...|
            // |           Are you sure you want to continue?    |
            // |                                                 |
            // |                       | Terminate |  | Cancel | | 
            // |_________________________________________________|

            if (OSVersion.HasTaskDialogs)
            {
                TaskDialog td = new TaskDialog
                {
                    WindowTitle = "Process Hacker", 
                    MainIcon = warning ? TaskDialogIcon.Warning : TaskDialogIcon.None, 
                    MainInstruction = "Do you want to " + action + "?",
                    PositionRelativeToWindow = true
                };

                if (!string.IsNullOrEmpty(message))
                    td.Content = message + " Are you sure you want to continue?";

                td.Buttons = new TaskDialogButton[]
                {
                    new TaskDialogButton((int)DialogResult.Yes, verbCaps),
                    new TaskDialogButton((int)DialogResult.No, "Cancel")
                };
                td.DefaultButton = (int)DialogResult.No;

                return td.Show(GetForegroundWindow()) == (int)DialogResult.Yes;
            }
            
            return MessageBox.Show(
                message + " Are you sure you want to " + action + "?",
                "Process Hacker",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning
                ) == DialogResult.Yes;
        }
Exemplo n.º 13
0
        private static bool ElevateIfRequired(IWin32Window window, string service,
            ServiceAccess access, string action)
        {
            if (Properties.Settings.Default.ElevationLevel == (int)ElevationLevel.Never)
                return false;

            if (OSVersion.HasUac && Program.ElevationType == TokenElevationType.Limited)
            {
                try
                {
                    using (var shandle = new ServiceHandle(service, access))
                    { }
                }
                catch (WindowsException ex)
                {
                    DialogResult result;

                    if (Properties.Settings.Default.ElevationLevel == (int)ElevationLevel.Elevate)
                    {
                        result = DialogResult.Yes;
                    }
                    else
                    {
                        TaskDialog td = new TaskDialog();

                        td.WindowTitle = "Process Hacker";
                        td.MainIcon = TaskDialogIcon.Warning;
                        td.MainInstruction = "Do you want to elevate the action?";
                        td.Content = "The action cannot be performed in the current security context. " +
                            "Do you want Process Hacker to prompt for the appropriate credentials and elevate the action?";

                        td.ExpandedInformation = "Error: " + ex.Message + " (0x" + ex.ErrorCode.ToString("x") + ")";
                        td.ExpandFooterArea = true;

                        td.Buttons = new TaskDialogButton[]
                        {
                            new TaskDialogButton((int)DialogResult.Yes, "Elevate\nPrompt for credentials and elevate the action."),
                            new TaskDialogButton((int)DialogResult.No, "Continue\nAttempt to perform the action without elevation.")
                        };
                        td.CommonButtons = TaskDialogCommonButtons.Cancel;
                        td.UseCommandLinks = true;
                        td.Callback = (taskDialog, args, userData) =>
                            {
                                if (args.Notification == TaskDialogNotification.Created)
                                {
                                    taskDialog.SetButtonElevationRequiredState((int)DialogResult.Yes, true);
                                }

                                return false;
                            };

                        result = (DialogResult)td.Show(window);
                    }

                    if (result == DialogResult.Yes)
                    {
                        Program.StartProcessHackerAdmin("-e -type service -action " + action + " -obj \"" +
                            service + "\" -hwnd " + window.Handle.ToString(), null, window.Handle);

                        return true;
                    }
                    else if (result == DialogResult.No)
                    {
                        return false;
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
        private void VirusTotalUploaderWindow_Load(object sender, EventArgs e)
        {
            labelFile.Text = string.Format("Uploading: {0}", processName);

            FileInfo finfo = new FileInfo(fileName);
            if (!finfo.Exists)
            {
                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog
                    {
                        PositionRelativeToWindow = true,
                        Content = "The selected file doesn't exist or couldnt be found!", 
                        MainInstruction = "File Location not Available!", 
                        WindowTitle = "System Error", 
                        MainIcon = TaskDialogIcon.CircleX, 
                        CommonButtons = TaskDialogCommonButtons.Ok
                    };

                    td.Show(Program.HackerWindow.Handle);
                }
                else
                {
                    MessageBox.Show(
                       this, "The selected file doesn't exist or couldnt be found!",
                       "System Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation
                       );
                }

                this.Close();
            }
            else if (finfo.Length >= 20971520 /* 20MB */)
            {
                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog
                    {
                        PositionRelativeToWindow = true,
                        Content = "This file is larger than 20MB, above the VirusTotal limit!", 
                        MainInstruction = "File is too large", 
                        WindowTitle = "VirusTotal Error", 
                        MainIcon = TaskDialogIcon.CircleX, 
                        CommonButtons = TaskDialogCommonButtons.Ok
                    };
                    td.Show(Program.HackerWindow.Handle);
                }
                else
                {
                     MessageBox.Show(
                        this, "This file is larger than 20MB and is above the VirusTotal size limit!",
                        "VirusTotal Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation
                        );
                }

                this.Close();
            }
            else
            {
                totalFileSize = finfo.Length;
            }

            uploadedLabel.Text = "Uploaded: Initializing";
            speedLabel.Text = "Speed: Initializing";

            ThreadTask getSessionTokenTask = new ThreadTask();

            getSessionTokenTask.RunTask += this.getSessionTokenTask_RunTask;
            getSessionTokenTask.Completed += this.getSessionTokenTask_Completed;
            getSessionTokenTask.Start();
        }
Exemplo n.º 15
0
        private static void PromptWithUpdate(Form form, UpdateItem bestUpdate, UpdateItem currentVersion, bool interactive)
        {
            if (form.InvokeRequired)
            {
                form.BeginInvoke(new MethodInvoker(() => PromptWithUpdate(form, bestUpdate, currentVersion, interactive)));
                return;
            }

            if (bestUpdate != currentVersion)
            {
                DialogResult dialogResult;

                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog();
                    td.PositionRelativeToWindow = true;
                    td.Content =
                        "Your Version: " + currentVersion.Version.ToString() +
                        "\nServer Version: " + bestUpdate.Version.ToString() + "\n\n" + "\n" + bestUpdate.Message;
                    td.MainInstruction = "Process Hacker update available";
                    td.WindowTitle = "Update available";
                    td.MainIcon = TaskDialogIcon.SecurityWarning;
                    td.Buttons = new TaskDialogButton[]
                    {
                        new TaskDialogButton((int)DialogResult.Yes, "Download"),
                        new TaskDialogButton((int)DialogResult.No, "Cancel"),
                    };

                    dialogResult = (DialogResult)td.Show(form);
                }
                else
                {
                    dialogResult = MessageBox.Show(
                        form,
                        "Your Version: " + currentVersion.Version.ToString() +
                        "\nServer Version: " + bestUpdate.Version.ToString() + "\n\n" + bestUpdate.Message +
                        "\n\nDo you want to download the update now?",
                        "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation
                        );
                }

                if (dialogResult == DialogResult.Yes)
                {
                    DownloadUpdate(form, bestUpdate);
                }

            }
            else if (interactive)
            {
                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog();
                    td.PositionRelativeToWindow = true;
                    td.Content =
                        "Your Version: " + currentVersion.Version.ToString() +
                        "\nServer Version: " + bestUpdate.Version.ToString();
                    td.MainInstruction = "Process Hacker is up-to-date";
                    td.WindowTitle = "No updates available";
                    td.MainIcon = TaskDialogIcon.SecuritySuccess;
                    td.CommonButtons = TaskDialogCommonButtons.Ok;
                    td.Show(form);
                }
                else
                {
                    MessageBox.Show(
                        form,
                        "Process Hacker is up-to-date.",
                        "No updates available", MessageBoxButtons.OK, MessageBoxIcon.Information
                        );
                }
            }
        }