示例#1
0
        private void removeMenuItem_Click(object sender, EventArgs e)
        {
            if (PhUtils.ShowConfirmMessage(
                    "remove",
                    "the selected privilege(s)",
                    "Removing privileges may reduce the functionality of the process, " +
                    "and is permanent for the lifetime of the process.",
                    false
                    ))
            {
                foreach (ListViewItem item in listPrivileges.SelectedItems)
                {
                    try
                    {
                        using (var thandle = _object.GetToken(TokenAccess.AdjustPrivileges))
                            thandle.SetPrivilege(item.Text, SePrivilegeAttributes.Removed);

                        item.Remove();
                    }
                    catch (Exception ex)
                    {
                        if (!PhUtils.ShowContinueMessage(
                                "Unable to remove " + item.Text,
                                ex
                                ))
                        {
                            return;
                        }
                    }
                }
            }
        }
示例#2
0
        private void enableMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listPrivileges.SelectedItems)
            {
                try
                {
                    using (var thandle = _object.GetToken(TokenAccess.AdjustPrivileges))
                        thandle.SetPrivilege(item.Text, SePrivilegeAttributes.Enabled);

                    if (item.SubItems[1].Text != "Default Enabled")
                    {
                        item.BackColor        = GetAttributeColor(SePrivilegeAttributes.Enabled);
                        item.SubItems[1].Text = GetAttributeString(SePrivilegeAttributes.Enabled);
                    }
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                            "Unable to enable " + item.Text,
                            ex
                            ))
                    {
                        return;
                    }
                }
            }
        }
示例#3
0
        public static void ReduceWorkingSet(IWin32Window window, int[] pids, string[] names, bool prompt)
        {
            if (ElevateIfRequired(window, pids, names,
                                  ProcessAccess.QueryInformation | ProcessAccess.SetQuota, "reduceworkingset"))
            {
                return;
            }

            if (prompt && !Prompt(window, pids, names, "reduce the working set of",
                                  "Reducing the working set of a process reduces its physical memory consumption. " +
                                  "Are you sure you want to continue?", true))
            {
                return;
            }

            for (int i = 0; i < pids.Length; i++)
            {
                try
                {
                    using (ProcessHandle phandle =
                               new ProcessHandle(pids[i], ProcessAccess.QueryInformation | ProcessAccess.SetQuota))
                        phandle.EmptyWorkingSet();
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                            "Unable to reduce the working set of " + GetName(pids, names, i),
                            ex
                            ))
                    {
                        return;
                    }
                }
            }
        }
示例#4
0
        public static void Resume(IWin32Window window, int[] pids, string[] names, bool prompt)
        {
            if (ElevateIfRequired(window, pids, names, ProcessAccess.SuspendResume, "resume"))
            {
                return;
            }

            if (prompt && !Prompt(window, pids, names, "resume",
                                  "Resuming a process will begin its execution. " +
                                  "Resuming a system process may lead to system instability. " +
                                  "Are you sure you want to continue?", true))
            {
                return;
            }

            for (int i = 0; i < pids.Length; i++)
            {
                try
                {
                    using (ProcessHandle phandle =
                               new ProcessHandle(pids[i], ProcessAccess.SuspendResume))
                        phandle.Resume();
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                            "Unable to resume " + GetName(pids, names, i),
                            ex
                            ))
                    {
                        return;
                    }
                }
            }
        }
示例#5
0
        private void closeHandleMenuItem_Click(object sender, EventArgs e)
        {
            lock (_listLock)
            {
                bool allGood = true;

                foreach (ListViewItem item in listHandles.SelectedItems)
                {
                    try
                    {
                        IntPtr handle = new IntPtr((int)BaseConverter.ToNumberParse(item.SubItems[2].Text));

                        using (ProcessHandle process =
                                   new ProcessHandle(_pid, Program.MinProcessGetHandleInformationRights))
                        {
                            Win32.DuplicateObject(process.Handle, handle, 0, 0, DuplicateOptions.CloseSource);
                        }
                    }
                    catch (Exception ex)
                    {
                        allGood = false;

                        if (!PhUtils.ShowContinueMessage(
                                "Unable to close the handle \"" + item.SubItems[1].Text + "\"",
                                ex
                                ))
                        {
                            return;
                        }
                    }
                }

                if (allGood)
                {
                    foreach (ListViewItem item in listHandles.SelectedItems)
                    {
                        item.Selected = false;
                    }
                }
            }
        }
示例#6
0
        public static bool Terminate(IWin32Window window, int[] pids, string[] names, bool prompt)
        {
            bool allGood = true;

            if (ElevateIfRequired(window, pids, names, ProcessAccess.Terminate, "terminate"))
            {
                return(false);
            }

            if (prompt && !Prompt(window, pids, names, "terminate",
                                  "Terminating a process will cause unsaved data to be lost. " +
                                  "Terminating a system process will cause system instability. " +
                                  "Are you sure you want to continue?", false))
            {
                return(false);
            }

            for (int i = 0; i < pids.Length; i++)
            {
                try
                {
                    using (ProcessHandle phandle =
                               new ProcessHandle(pids[i], ProcessAccess.Terminate))
                        phandle.Terminate();
                }
                catch (Exception ex)
                {
                    allGood = false;

                    if (!PhUtils.ShowContinueMessage(
                            "Unable to terminate " + GetName(pids, names, i),
                            ex
                            ))
                    {
                        return(false);
                    }
                }
            }

            return(allGood);
        }
示例#7
0
        private void closeMenuItem_Click(object sender, EventArgs e)
        {
            List <ListViewItem> remove = new List <ListViewItem>();

            foreach (int index in listHandles.SelectedIndices)
            {
                if (listHandles.Items[index].SubItems[1].Text == "DLL" ||
                    listHandles.Items[index].SubItems[1].Text == "Mapped File")
                {
                    continue;
                }

                try
                {
                    IntPtr handle = new IntPtr((int)BaseConverter.ToNumberParse(listHandles.Items[index].SubItems[3].Text));

                    using (ProcessHandle process =
                               new ProcessHandle(((SystemHandleEntry)listHandles.SelectedItems[0].Tag).ProcessId,
                                                 ProcessAccess.DupHandle))
                    {
                        Win32.DuplicateObject(process.Handle, handle, 0, 0, DuplicateOptions.CloseSource);
                        remove.Add(listHandles.Items[index]);
                    }
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                            "Unable to close the handle \"" + listHandles.Items[index].SubItems[2].Text + "\"",
                            ex
                            ))
                    {
                        return;
                    }
                }
            }

            foreach (ListViewItem item in remove)
            {
                item.Remove();
            }
        }