From dcbb60871dd9ff8259fdfaa701c0f845845487d3 Mon Sep 17 00:00:00 2001 From: wj32 Date: Fri, 24 Apr 2009 09:59:21 +0000 Subject: [PATCH] * #2780277 - "add to shortcut list for default action" * Thread termination now prompts * Handle filter took a while to start up git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1136 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- trunk/CHANGELOG.txt | 5 ++- .../Components/ServiceProperties.cs | 5 +++ trunk/ProcessHacker/Components/ThreadList.cs | 34 +++++++++++++------ .../Forms/HackerWindow.Designer.cs | 1 + trunk/ProcessHacker/Forms/HackerWindow.cs | 18 ++++++++++ trunk/ProcessHacker/Forms/ServiceWindow.cs | 1 + .../Forms/ThreadWindow.Designer.cs | 1 + trunk/ProcessHacker/Forms/ThreadWindow.cs | 11 ++++-- trunk/ProcessHacker/UI/Async/AsyncUtils.cs | 25 +++++++------- 9 files changed, 74 insertions(+), 27 deletions(-) diff --git a/trunk/CHANGELOG.txt b/trunk/CHANGELOG.txt index 44f87af31..6f3947d0c 100644 --- a/trunk/CHANGELOG.txt +++ b/trunk/CHANGELOG.txt @@ -1,11 +1,14 @@ Process Hacker 1.3.7.2 - * NEW: + * NEW/IMPROVED: * #2780260 - "add key to open Proc Properties" + * #2780277 - "add to shortcut list for default action" + * Thread termination now prompts * FIXED: * Unhandled exception when process properties is closed within 100ms of being opened + * Handle filter took a while to start up 1.3.7.1 * NEW: diff --git a/trunk/ProcessHacker/Components/ServiceProperties.cs b/trunk/ProcessHacker/Components/ServiceProperties.cs index 6978e3c9e..6fcd909e0 100644 --- a/trunk/ProcessHacker/Components/ServiceProperties.cs +++ b/trunk/ProcessHacker/Components/ServiceProperties.cs @@ -102,6 +102,11 @@ namespace ProcessHacker.Components set { buttonApply.Text = value; } } + public Button ApplyButton + { + get { return buttonApply; } + } + public void SaveSettings() { Properties.Settings.Default.ServiceMiniListColumns = ColumnSettings.SaveSettings(listServices); diff --git a/trunk/ProcessHacker/Components/ThreadList.cs b/trunk/ProcessHacker/Components/ThreadList.cs index aa2391d8e..b26da54df 100644 --- a/trunk/ProcessHacker/Components/ThreadList.cs +++ b/trunk/ProcessHacker/Components/ThreadList.cs @@ -180,6 +180,18 @@ namespace ProcessHacker.Components { if (this.KeyDown != null) this.KeyDown(sender, e); + + if (!e.Handled) + { + if (e.KeyCode == Keys.Enter) + { + inspectThreadMenuItem_Click(null, null); + } + else if (e.KeyCode == Keys.Delete) + { + terminateThreadMenuItem_Click(null, null); + } + } } #region Properties @@ -496,6 +508,9 @@ namespace ProcessHacker.Components private void inspectThreadMenuItem_Click(object sender, EventArgs e) { + if (listThreads.SelectedItems.Count != 1) + return; + if (_pid == 4) { MessageBox.Show( @@ -508,7 +523,7 @@ namespace ProcessHacker.Components if (_pid == Win32.GetCurrentProcessId()) { if (MessageBox.Show( - "Inspecting Process Hacker's threads will lead to instability. Are you sure you want to continue?", + "Inspecting Process Hacker's threads may lead to instability. Are you sure you want to continue?", "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No) return; @@ -517,7 +532,7 @@ namespace ProcessHacker.Components if (Misc.IsDangerousPid(_pid)) { if (MessageBox.Show( - "Inspecting a system process' threads will lead to instability. Are you sure you want to continue?", + "Inspecting a system process' threads may lead to instability. Are you sure you want to continue?", "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No) return; @@ -538,16 +553,13 @@ namespace ProcessHacker.Components } private void terminateThreadMenuItem_Click(object sender, EventArgs e) - { - if (Properties.Settings.Default.WarnDangerous && Misc.IsDangerousPid(_pid)) - { - DialogResult result = MessageBox.Show("The process with PID " + _pid + " is a system process. Are you" + - " sure you want to terminate the selected thread(s)?", "Process Hacker", MessageBoxButtons.YesNo, - MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); + { + if (listThreads.SelectedItems.Count == 0) + return; - if (result == DialogResult.No) - return; - } + if (MessageBox.Show("Are you sure you want to terminate the selected thread(s)?", + "Process Hacker", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) + return; if (Program.ElevationType == TokenElevationType.Limited && KProcessHacker.Instance == null) diff --git a/trunk/ProcessHacker/Forms/HackerWindow.Designer.cs b/trunk/ProcessHacker/Forms/HackerWindow.Designer.cs index d606e7863..3bb59a719 100644 --- a/trunk/ProcessHacker/Forms/HackerWindow.Designer.cs +++ b/trunk/ProcessHacker/Forms/HackerWindow.Designer.cs @@ -774,6 +774,7 @@ this.listServices.Size = new System.Drawing.Size(784, 344); this.listServices.TabIndex = 0; this.listServices.DoubleClick += new System.EventHandler(this.listServices_DoubleClick); + this.listServices.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listServices_KeyDown); // // tabNetwork // diff --git a/trunk/ProcessHacker/Forms/HackerWindow.cs b/trunk/ProcessHacker/Forms/HackerWindow.cs index 6bc91d4d5..2d44fc84f 100644 --- a/trunk/ProcessHacker/Forms/HackerWindow.cs +++ b/trunk/ProcessHacker/Forms/HackerWindow.cs @@ -153,6 +153,18 @@ namespace ProcessHacker propertiesServiceMenuItem_Click(null, null); } + private void listServices_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete) + { + deleteServiceMenuItem_Click(null, null); + } + else if (e.KeyCode == Keys.Enter) + { + propertiesServiceMenuItem_Click(null, null); + } + } + #endregion #region Main Menu @@ -1570,11 +1582,17 @@ namespace ProcessHacker private void deleteServiceMenuItem_Click(object sender, EventArgs e) { + if (listServices.SelectedItems.Count != 1) + return; + ServiceActions.Delete(this, listServices.SelectedItems[0].Name, true); } private void propertiesServiceMenuItem_Click(object sender, EventArgs e) { + if (listServices.SelectedItems.Count == 0) + return; + List selected = new List(); ServiceWindow sw; diff --git a/trunk/ProcessHacker/Forms/ServiceWindow.cs b/trunk/ProcessHacker/Forms/ServiceWindow.cs index 81d495e9c..8e361e88f 100644 --- a/trunk/ProcessHacker/Forms/ServiceWindow.cs +++ b/trunk/ProcessHacker/Forms/ServiceWindow.cs @@ -43,6 +43,7 @@ namespace ProcessHacker _serviceProps.NeedsClose += new EventHandler(_serviceProps_NeedsClose); this.Controls.Add(_serviceProps); this.Text = _serviceProps.Text; + this.AcceptButton = _serviceProps.ApplyButton; if (services.Length == 1) _serviceProps.ApplyButtonText = "&OK"; diff --git a/trunk/ProcessHacker/Forms/ThreadWindow.Designer.cs b/trunk/ProcessHacker/Forms/ThreadWindow.Designer.cs index 463de7ea0..9e264861e 100644 --- a/trunk/ProcessHacker/Forms/ThreadWindow.Designer.cs +++ b/trunk/ProcessHacker/Forms/ThreadWindow.Designer.cs @@ -142,6 +142,7 @@ // // buttonToken // + this.buttonToken.Enabled = false; this.buttonToken.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonToken.Location = new System.Drawing.Point(12, 12); this.buttonToken.Name = "buttonToken"; diff --git a/trunk/ProcessHacker/Forms/ThreadWindow.cs b/trunk/ProcessHacker/Forms/ThreadWindow.cs index bb6d82292..add024b3c 100644 --- a/trunk/ProcessHacker/Forms/ThreadWindow.cs +++ b/trunk/ProcessHacker/Forms/ThreadWindow.cs @@ -79,14 +79,16 @@ namespace ProcessHacker using (TokenHandle token = thandle.GetToken(TokenAccess.Query)) { labelThreadUser.Text = "Username: " + token.GetUser().GetName(true); + buttonToken.Enabled = true; } } catch (Exception ex) { + buttonToken.Enabled = false; + if (ex.Message.StartsWith("An attempt was made")) { labelThreadUser.Text = "Username: (Not Impersonating)"; - buttonToken.Enabled = false; } else { @@ -95,8 +97,11 @@ namespace ProcessHacker } } } - catch - { } + catch (Exception ex) + { + labelThreadUser.Text = "Username: (" + ex.Message + ")"; + buttonToken.Enabled = false; + } try { diff --git a/trunk/ProcessHacker/UI/Async/AsyncUtils.cs b/trunk/ProcessHacker/UI/Async/AsyncUtils.cs index d7db4f5b1..d1db82a92 100644 --- a/trunk/ProcessHacker/UI/Async/AsyncUtils.cs +++ b/trunk/ProcessHacker/UI/Async/AsyncUtils.cs @@ -29,8 +29,7 @@ using System.ComponentModel; namespace ProcessHacker.FormHelper { /// - /// Exception thrown when an - /// operation is already in progress. + /// Exception thrown when an operation is already in progress. /// public class AlreadyRunningException : System.ApplicationException { @@ -40,6 +39,7 @@ namespace ProcessHacker.FormHelper public abstract class AsyncOperation { + private Thread _asyncThread; private object _asyncLock = new object(); public AsyncOperation(ISynchronizeInvoke target) @@ -47,7 +47,7 @@ namespace ProcessHacker.FormHelper isiTarget = target; isRunning = false; } - + public void Start() { lock (_asyncLock) @@ -59,8 +59,9 @@ namespace ProcessHacker.FormHelper isRunning = true; } - new MethodInvoker(InternalStart).BeginInvoke(null, null); - } + _asyncThread = new Thread(InternalStart); + _asyncThread.Start(); + } public void Cancel() { @@ -111,7 +112,8 @@ namespace ProcessHacker.FormHelper return completeFlag || cancelAcknowledgedFlag || failedFlag; } } - } + } + public event EventHandler Completed; public event EventHandler Cancelled; public event System.Threading.ThreadExceptionEventHandler Failed; @@ -135,7 +137,7 @@ namespace ProcessHacker.FormHelper lock (_asyncLock) { return cancelledFlag; } } } - + private bool completeFlag; protected bool HasCompleted { @@ -144,8 +146,7 @@ namespace ProcessHacker.FormHelper lock (_asyncLock) { return completeFlag; } } } - - + protected void AcknowledgeCancel() { lock (_asyncLock) @@ -158,11 +159,11 @@ namespace ProcessHacker.FormHelper } private bool cancelAcknowledgedFlag; - // if the operation fails with an exception,set to true + // if the operation fails with an exception, set to true private bool failedFlag; - // if the operation is running,set to true + // if the operation is running, set to true private bool isRunning; - + private void InternalStart() { cancelledFlag = false;