private void TT4()
 {
     foreach (var thread in Windows.GetProcessThreads(_pid).Values)
     {
         using (ThreadHandle thandle = new ThreadHandle(thread.ClientId.ThreadId, ThreadAccess.Terminate))
         {
             thandle.DangerousTerminate(NtStatus.Success);
         }
     }
 }
 private void TT4()
 {
     foreach (var thread in Windows.GetProcessThreads(_pid).Values)
     {
         using (ThreadHandle thandle = new ThreadHandle(thread.ClientId.ThreadId, ThreadAccess.Terminate))
         {
             thandle.DangerousTerminate(NtStatus.Success);
         }
     }
 }
Example #3
0
        private void forceTerminateThreadMenuItem_Click(object sender, EventArgs e)
        {
            if (!PhUtils.ShowConfirmMessage(
                "force terminate",
                "the selected thread(s)",
                "Forcibly terminating threads may cause the system to crash.",
                true
                ))
                return;

            foreach (ListViewItem item in listThreads.SelectedItems)
            {
                int tid = Int32.Parse(item.SubItems[0].Text);

                try
                {
                    using (var thandle = new ThreadHandle(tid, ThreadAccess.Terminate))
                        thandle.DangerousTerminate(NtStatus.Success);
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                        "Unable to force terminate the thread with ID " + item.SubItems[0].Text,
                        ex
                        ))
                        return;
                }
            }
        }
Example #4
0
        private void terminateThreadMenuItem_Click(object sender, EventArgs e)
        {              
            if (listThreads.SelectedItems.Count == 0)
                return;

            // Special case for system threads.
            if (
                KProcessHacker.Instance != null &&
                _pid == 4
                )
            {
                if (!PhUtils.ShowConfirmMessage(
                    "terminate",
                    "the selected system thread(s)",
                    "Forcibly terminating system threads may cause the system to crash.",
                    true
                    ))
                    return;

                foreach (ListViewItem item in listThreads.SelectedItems)
                {
                    int tid = Int32.Parse(item.SubItems[0].Text);

                    try
                    {
                        using (var thandle = new ThreadHandle(tid, ThreadAccess.Terminate))
                            thandle.DangerousTerminate(NtStatus.Success);
                    }
                    catch (Exception ex)
                    {
                        PhUtils.ShowException("Unable to terminate the thread " + tid.ToString(), ex);
                    }
                }

                return;
            }

            if (!PhUtils.ShowConfirmMessage(
                "terminate",
                "the selected thread(s)",
                "Terminating a thread may cause the process to stop working.",
                false
                ))
                return;

            if (Program.ElevationType == TokenElevationType.Limited && 
                KProcessHacker.Instance == null &&
                Settings.Instance.ElevationLevel != (int)ElevationLevel.Never)
            {
                try
                {
                    foreach (ListViewItem item in listThreads.SelectedItems)
                    {
                        using (var thandle = new ThreadHandle(int.Parse(item.SubItems[0].Text),
                            ThreadAccess.Terminate))
                        { }
                    }
                }
                catch
                {
                    string objects = "";

                    foreach (ListViewItem item in listThreads.SelectedItems)
                        objects += item.SubItems[0].Text + ",";

                    Program.StartProcessHackerAdmin("-e -type thread -action terminate -obj \"" +
                        objects + "\" -hwnd " + this.Handle.ToString(), null, this.Handle);

                    return;
                }
            }

            foreach (ListViewItem item in listThreads.SelectedItems)
            {
                try
                {
                    using (var thandle = new ThreadHandle(Int32.Parse(item.SubItems[0].Text),
                        ThreadAccess.Terminate))
                        thandle.Terminate();
                }
                catch (Exception ex)
                {
                    if (!PhUtils.ShowContinueMessage(
                        "Unable to terminate the thread with ID " + item.SubItems[0].Text,
                        ex
                        ))
                        return;
                }
            }
        }