From 15180b9956061aafcf4820dbdbc76cdf20121414 Mon Sep 17 00:00:00 2001 From: wj32 Date: Wed, 15 Apr 2009 10:42:19 +0000 Subject: [PATCH] Elevation button in Options now spawns a child options window instead of restarting Process Hacker elevated git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1066 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- trunk/CHANGELOG.txt | 4 +- trunk/ProcessHacker/Common/Misc.cs | 23 ++ .../ProcessHacker/Components/ColorModifier.cs | 8 + trunk/ProcessHacker/Forms/HackerWindow.cs | 14 +- .../Forms/OptionsWindow.Designer.cs | 34 +- trunk/ProcessHacker/Forms/OptionsWindow.cs | 386 +++++++++++------- trunk/ProcessHacker/Forms/OptionsWindow.resx | 3 - trunk/ProcessHacker/Forms/ResultsWindow.cs | 13 +- trunk/ProcessHacker/ProcessHacker.csproj | 1 + trunk/ProcessHacker/Program/ExtendedCmd.cs | 19 +- trunk/ProcessHacker/Program/Program.cs | 78 +++- trunk/ProcessHacker/UI/WindowFromHandle.cs | 22 + 12 files changed, 372 insertions(+), 233 deletions(-) create mode 100644 trunk/ProcessHacker/UI/WindowFromHandle.cs diff --git a/trunk/CHANGELOG.txt b/trunk/CHANGELOG.txt index 9053ed8a8..a228b1646 100644 --- a/trunk/CHANGELOG.txt +++ b/trunk/CHANGELOG.txt @@ -1,9 +1,11 @@ Process Hacker 1.3.6.6 - * NEW: + * NEW/IMPROVED: * Proper symbol support with dbghelp.dll * Aggressive mode (start with "-a" command line option) + * Elevation button in Options now spawns a child options window instead of + restarting Process Hacker elevated * FIXED: * Service properties Key handle leak * Handle deletion detection diff --git a/trunk/ProcessHacker/Common/Misc.cs b/trunk/ProcessHacker/Common/Misc.cs index 3ebef95f0..97452218e 100644 --- a/trunk/ProcessHacker/Common/Misc.cs +++ b/trunk/ProcessHacker/Common/Misc.cs @@ -28,6 +28,7 @@ using System.Text; using System.Windows.Forms; using Aga.Controls.Tree; using System.Collections.Generic; +using System.Drawing; namespace ProcessHacker { @@ -250,6 +251,20 @@ namespace ProcessHacker return str; } + public static Rectangle FitRectangle(Rectangle rect, Rectangle bounds) + { + if (rect.X < bounds.Left) + rect.X = bounds.Left; + if (rect.Y < bounds.Top) + rect.Y = bounds.Top; + if (rect.X + rect.Width > bounds.Width) + rect.X = bounds.Width - rect.Width; + if (rect.Y + rect.Height > bounds.Height) + rect.Y = bounds.Height - rect.Height; + + return rect; + } + /// /// Gets the base address of the currently running kernel. /// @@ -713,6 +728,14 @@ namespace ProcessHacker return str.ToString(); } + public static Rectangle RectangleFromString(string s) + { + var split = s.Split(','); + + return new Rectangle(int.Parse(split[0]), int.Parse(split[1]), + int.Parse(split[2]), int.Parse(split[3])); + } + /// /// Selects all of the specified items. /// diff --git a/trunk/ProcessHacker/Components/ColorModifier.cs b/trunk/ProcessHacker/Components/ColorModifier.cs index 02524113f..d5c9a393a 100644 --- a/trunk/ProcessHacker/Components/ColorModifier.cs +++ b/trunk/ProcessHacker/Components/ColorModifier.cs @@ -31,6 +31,8 @@ namespace ProcessHacker.Components { public partial class ColorModifier : UserControl { + public event EventHandler ColorChanged; + private Color _color; public ColorModifier() @@ -48,6 +50,9 @@ namespace ProcessHacker.Components { _color = cd.Color; panelColor.BackColor = cd.Color; + + if (this.ColorChanged != null) + this.ColorChanged(this, new EventArgs()); } } @@ -58,6 +63,9 @@ namespace ProcessHacker.Components { _color = value; panelColor.BackColor = value; + + if (this.ColorChanged != null) + this.ColorChanged(this, new EventArgs()); } } diff --git a/trunk/ProcessHacker/Forms/HackerWindow.cs b/trunk/ProcessHacker/Forms/HackerWindow.cs index 1ea43be1b..ef883b6c4 100644 --- a/trunk/ProcessHacker/Forms/HackerWindow.cs +++ b/trunk/ProcessHacker/Forms/HackerWindow.cs @@ -2257,18 +2257,6 @@ namespace ProcessHacker private void LoadApplyCommandLineArgs() { tabControl.SelectedTab = tabControl.TabPages["tab" + Program.SelectTab]; - - if (Program.ShowOptions) - { - OptionsWindow options = new OptionsWindow(); - - options.TopMost = this.TopMost; - options.ShowDialog(); - - processP.Interval = Properties.Settings.Default.RefreshInterval; - serviceP.Interval = Properties.Settings.Default.RefreshInterval; - networkP.Interval = Properties.Settings.Default.RefreshInterval; - } } public HackerWindow() @@ -2293,7 +2281,7 @@ namespace ProcessHacker this.ResumeLayout(); if ((!Properties.Settings.Default.StartHidden && !Program.StartHidden) || - Program.StartVisible || Program.ShowOptions) + Program.StartVisible) { this.Visible = true; } diff --git a/trunk/ProcessHacker/Forms/OptionsWindow.Designer.cs b/trunk/ProcessHacker/Forms/OptionsWindow.Designer.cs index ebb57fbf8..e431afe3a 100644 --- a/trunk/ProcessHacker/Forms/OptionsWindow.Designer.cs +++ b/trunk/ProcessHacker/Forms/OptionsWindow.Designer.cs @@ -93,9 +93,9 @@ this.buttonDbghelpBrowse = new System.Windows.Forms.Button(); this.textDbghelpPath = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); - this.label22 = new System.Windows.Forms.Label(); this.toolTipProvider = new System.Windows.Forms.ToolTip(this.components); this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonApply = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.textUpdateInterval)).BeginInit(); this.tabControl.SuspendLayout(); this.tabGeneral.SuspendLayout(); @@ -152,7 +152,7 @@ // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonOK.Location = new System.Drawing.Point(281, 385); + this.buttonOK.Location = new System.Drawing.Point(200, 385); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 2; @@ -912,16 +912,6 @@ this.toolTipProvider.SetToolTip(this.label9, "Select the most recent version of dbghelp.dll available, usually distributed with" + " Debugging Tools for Windows."); // - // label22 - // - this.label22.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.label22.AutoSize = true; - this.label22.Location = new System.Drawing.Point(12, 390); - this.label22.Name = "label22"; - this.label22.Size = new System.Drawing.Size(234, 13); - this.label22.TabIndex = 10; - this.label22.Text = "Tip: Hover over an item to get a description of it."; - // // toolTipProvider // this.toolTipProvider.AutomaticDelay = 250; @@ -934,7 +924,7 @@ // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonCancel.Location = new System.Drawing.Point(362, 385); + this.buttonCancel.Location = new System.Drawing.Point(281, 385); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 11; @@ -942,14 +932,27 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // buttonApply + // + this.buttonApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonApply.Enabled = false; + this.buttonApply.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.buttonApply.Location = new System.Drawing.Point(362, 385); + this.buttonApply.Name = "buttonApply"; + this.buttonApply.Size = new System.Drawing.Size(75, 23); + this.buttonApply.TabIndex = 11; + this.buttonApply.Text = "&Apply"; + this.buttonApply.UseVisualStyleBackColor = true; + this.buttonApply.Click += new System.EventHandler(this.buttonApply_Click); + // // OptionsWindow // this.AcceptButton = this.buttonOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(449, 420); + this.Controls.Add(this.buttonApply); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.label22); this.Controls.Add(this.tabControl); this.Controls.Add(this.buttonOK); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; @@ -979,7 +982,6 @@ this.tabSymbols.ResumeLayout(false); this.tabSymbols.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } @@ -1024,7 +1026,6 @@ private System.Windows.Forms.Label label21; private System.Windows.Forms.Button buttonFont; private System.Windows.Forms.ToolTip toolTipProvider; - private System.Windows.Forms.Label label22; private System.Windows.Forms.NumericUpDown textIconMenuProcesses; private System.Windows.Forms.Label label23; private System.Windows.Forms.CheckBox checkHideWhenClosed; @@ -1052,5 +1053,6 @@ private System.Windows.Forms.Button buttonDbghelpBrowse; private System.Windows.Forms.TextBox textDbghelpPath; private System.Windows.Forms.CheckBox checkUndecorate; + private System.Windows.Forms.Button buttonApply; } } \ No newline at end of file diff --git a/trunk/ProcessHacker/Forms/OptionsWindow.cs b/trunk/ProcessHacker/Forms/OptionsWindow.cs index a2af1117d..c58a7bb5d 100644 --- a/trunk/ProcessHacker/Forms/OptionsWindow.cs +++ b/trunk/ProcessHacker/Forms/OptionsWindow.cs @@ -27,6 +27,8 @@ using System.Windows.Forms; using Aga.Controls.Tree; using ProcessHacker.Symbols; using ProcessHacker.UI; +using ProcessHacker.Components; +using System.Threading; namespace ProcessHacker { @@ -35,11 +37,166 @@ namespace ProcessHacker private string _oldDbghelp; private string _oldTaskMgrDebugger; private Font _font; + private bool _dontApply; public OptionsWindow() + : this(false) + { } + + public OptionsWindow(bool dontApply) { InitializeComponent(); + _dontApply = dontApply; + this.InitializeHighlightingColors(); + this.LoadSettings(); + + foreach (TabPage tab in tabControl.TabPages) + { + foreach (Control c in tab.Controls) + { + if (c is CheckBox || c is ListView) + c.Click += (sender, e) => this.EnableApplyButton(); + else if (c is TextBox) + (c as TextBox).TextChanged += (sender, e) => this.EnableApplyButton(); + else if (c is ComboBox) + (c as ComboBox).SelectedIndexChanged += (sender, e) => this.EnableApplyButton(); + else if (c is NumericUpDown) + (c as NumericUpDown).ValueChanged += (sender, e) => this.EnableApplyButton(); + else if (c is ColorModifier) + (c as ColorModifier).ColorChanged += (sender, e) => this.EnableApplyButton(); + else if (c is Button || c is Label) + ; // Nothing + else + c.Click += (sender, e) => this.EnableApplyButton(); + } + } + } + + public TabPage SelectedTab + { + get { return tabControl.SelectedTab; } + set { tabControl.SelectedTab = value; } + } + + public TabControl.TabPageCollection TabPages + { + get { return tabControl.TabPages; } + } + + private void OptionsWindow_Load(object sender, EventArgs e) + { + if (Program.ElevationType == Win32.TOKEN_ELEVATION_TYPE.TokenElevationTypeLimited) + { + buttonChangeReplaceTaskManager.SetShieldIcon(true); + } + else + { + buttonChangeReplaceTaskManager.Visible = false; + } + } + + private void OptionsWindow_FormClosing(object sender, FormClosingEventArgs e) + { + //if (!_autoClosed) + //{ + // var result = MessageBox.Show("Do you want to save any changes you have made?", "Process Hacker", + // MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + + // if (result == DialogResult.Yes) + // this.ApplySettings(); + // else if (result == DialogResult.Cancel) + // e.Cancel = true; + //} + } + + private void EnableApplyButton() + { + if (!_dontApply) + buttonApply.Enabled = true; + } + + private void AddToList(string key, string description, string longDescription) + { + listHighlightingColors.Items.Add(new ListViewItem() + { + Name = key, + Text = description, + ToolTipText = longDescription + }); + } + + private void InitializeHighlightingColors() + { + AddToList("ColorOwnProcesses", "Own Processes", + "Processes running under the same user account as Process Hacker."); + AddToList("ColorSystemProcesses", "System Processes", + "Processes running under the NT AUTHORITY\\SYSTEM user account."); + AddToList("ColorServiceProcesses", "Service Processes", + "Processes which host one or more services."); + AddToList("ColorDebuggedProcesses", "Debugged Processes", + "Processes that are currently being debugged."); + AddToList("ColorElevatedProcesses", "Elevated Processes", + "Processes with full privileges on a Windows Vista system with UAC enabled."); + AddToList("ColorJobProcesses", "Job Processes", + "Processes associated with a job."); + AddToList("ColorDotNetProcesses", ".NET Processes", + ".NET, or managed processes."); + AddToList("ColorPackedProcesses", "Packed/Dangerous Processes", + "Executables are sometimes \"packed\" to reduce their size.\n" + + "\"Dangerous processes\" includes processes with invalid signatures and unverified " + + "processes with the name of a system process."); + AddToList("ColorSuspended", "Suspended Threads", + "Threads that are suspended from execution."); + AddToList("ColorGuiThreads", "GUI Threads", + "Threads that have made at least one GUI-related system call."); + } + + private void listHighlightingColors_DoubleClick(object sender, EventArgs e) + { + listHighlightingColors.SelectedItems[0].Checked = !listHighlightingColors.SelectedItems[0].Checked; + + ColorDialog cd = new ColorDialog(); + + cd.Color = listHighlightingColors.SelectedItems[0].BackColor; + + if (cd.ShowDialog() == DialogResult.OK) + listHighlightingColors.SelectedItems[0].BackColor = cd.Color; + } + + private void textUpdateInterval_Leave(object sender, EventArgs e) + { + try + { + Properties.Settings.Default.RefreshInterval = Int32.Parse(textUpdateInterval.Value.ToString()); + } + catch + { + MessageBox.Show("The entered value is not valid.", "Process Hacker", MessageBoxButtons.OK, + MessageBoxIcon.Error); + + textUpdateInterval.Focus(); + } + } + + private void textIconMenuProcesses_Leave(object sender, EventArgs e) + { + try + { + Properties.Settings.Default.IconMenuProcessCount = Int32.Parse(textIconMenuProcesses.Value.ToString()); + } + catch + { + MessageBox.Show("The entered value is not valid.", "Process Hacker", MessageBoxButtons.OK, + MessageBoxIcon.Error); + + textIconMenuProcesses.Focus(); + } + } + + private void LoadSettings() + { + // General _font = Properties.Settings.Default.Font; buttonFont.Font = _font; textUpdateInterval.Value = Properties.Settings.Default.RefreshInterval; @@ -62,11 +219,21 @@ namespace ProcessHacker textImposterNames.Text = Properties.Settings.Default.ImposterNames; + // Highlighting textHighlightingDuration.Value = Properties.Settings.Default.HighlightingDuration; colorNewProcesses.Color = Properties.Settings.Default.ColorNew; colorRemovedProcesses.Color = Properties.Settings.Default.ColorRemoved; - this.InitializeHighlightingColors(); + foreach (ListViewItem item in listHighlightingColors.Items) + { + Color c = (Color)Properties.Settings.Default[item.Name]; + bool use = (bool)Properties.Settings.Default["Use" + item.Name]; + + item.BackColor = c; + item.Checked = use; + } + + // Plotting checkPlotterAntialias.Checked = Properties.Settings.Default.PlotterAntialias; colorCPUKT.Color = Properties.Settings.Default.PlotterCPUKernelColor; colorCPUUT.Color = Properties.Settings.Default.PlotterCPUUserColor; @@ -75,6 +242,7 @@ namespace ProcessHacker colorIORO.Color = Properties.Settings.Default.PlotterIOROColor; colorIOW.Color = Properties.Settings.Default.PlotterIOWColor; + // Replace Task Manager // See if we can write to the key. try { @@ -126,129 +294,17 @@ namespace ProcessHacker checkReplaceTaskManager.Enabled = false; } + // Symbols try { _oldDbghelp = textDbghelpPath.Text = Properties.Settings.Default.DbgHelpPath; textSearchPath.Text = Properties.Settings.Default.DbgHelpSearchPath; - checkUndecorate.Checked = (SymbolProvider.Options & Win32.SYMBOL_OPTIONS.UndName) != 0; + checkUndecorate.Checked = Properties.Settings.Default.DbgHelpUndecorate; } catch { } checkShowTrayIcon_CheckedChanged(null, null); - } - - private void OptionsWindow_Load(object sender, EventArgs e) - { - if (Program.ElevationType == Win32.TOKEN_ELEVATION_TYPE.TokenElevationTypeLimited) - { - buttonChangeReplaceTaskManager.SetShieldIcon(true); - } - else - { - buttonChangeReplaceTaskManager.Visible = false; - } - } - - private void OptionsWindow_FormClosing(object sender, FormClosingEventArgs e) - { - //if (!_autoClosed) - //{ - // var result = MessageBox.Show("Do you want to save any changes you have made?", "Process Hacker", - // MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); - - // if (result == DialogResult.Yes) - // this.ApplySettings(); - // else if (result == DialogResult.Cancel) - // e.Cancel = true; - //} - } - - private void AddToList(string key, string description, string longDescription) - { - listHighlightingColors.Items.Add(new ListViewItem() - { - Name = key, - Text = description, - ToolTipText = longDescription - }); - } - - private void InitializeHighlightingColors() - { - AddToList("ColorOwnProcesses", "Own Processes", - "Processes running under the same user account as Process Hacker."); - AddToList("ColorSystemProcesses", "System Processes", - "Processes running under the NT AUTHORITY\\SYSTEM user account."); - AddToList("ColorServiceProcesses", "Service Processes", - "Processes which host one or more services."); - AddToList("ColorDebuggedProcesses", "Debugged Processes", - "Processes that are currently being debugged."); - AddToList("ColorElevatedProcesses", "Elevated Processes", - "Processes with full privileges on a Windows Vista system with UAC enabled."); - AddToList("ColorJobProcesses", "Job Processes", - "Processes associated with a job."); - AddToList("ColorDotNetProcesses", ".NET Processes", - ".NET, or managed processes."); - AddToList("ColorPackedProcesses", "Packed/Dangerous Processes", - "Executables are sometimes \"packed\" to reduce their size.\n" + - "\"Dangerous processes\" includes processes with invalid signatures and unverified " + - "processes with the name of a system process."); - AddToList("ColorSuspended", "Suspended Threads", - "Threads that are suspended from execution."); - AddToList("ColorGuiThreads", "GUI Threads", - "Threads that have made at least one GUI-related system call."); - - foreach (ListViewItem item in listHighlightingColors.Items) - { - Color c = (Color)Properties.Settings.Default[item.Name]; - bool use = (bool)Properties.Settings.Default["Use" + item.Name]; - - item.BackColor = c; - item.Checked = use; - } - } - - private void listHighlightingColors_DoubleClick(object sender, EventArgs e) - { - listHighlightingColors.SelectedItems[0].Checked = !listHighlightingColors.SelectedItems[0].Checked; - - ColorDialog cd = new ColorDialog(); - - cd.Color = listHighlightingColors.SelectedItems[0].BackColor; - - if (cd.ShowDialog() == DialogResult.OK) - listHighlightingColors.SelectedItems[0].BackColor = cd.Color; - } - - private void textUpdateInterval_Leave(object sender, EventArgs e) - { - try - { - Properties.Settings.Default.RefreshInterval = Int32.Parse(textUpdateInterval.Value.ToString()); - } - catch - { - MessageBox.Show("The entered value is not valid.", "Process Hacker", MessageBoxButtons.OK, - MessageBoxIcon.Error); - - textUpdateInterval.Focus(); - } - } - - private void textIconMenuProcesses_Leave(object sender, EventArgs e) - { - try - { - Properties.Settings.Default.IconMenuProcessCount = Int32.Parse(textIconMenuProcesses.Value.ToString()); - } - catch - { - MessageBox.Show("The entered value is not valid.", "Process Hacker", MessageBoxButtons.OK, - MessageBoxIcon.Error); - - textIconMenuProcesses.Focus(); - } } private void SaveSettings() @@ -274,16 +330,6 @@ namespace ProcessHacker Properties.Settings.Default.PlotterStep = (int)textStep.Value; ProcessHacker.Components.Plotter.GlobalMoveStep = Properties.Settings.Default.PlotterStep; - Program.ImposterNames = new System.Collections.Specialized.StringCollection(); - - foreach (string s in Properties.Settings.Default.ImposterNames.Split(',')) - Program.ImposterNames.Add(s.Trim()); - - Program.HackerWindow.NotifyIcon.Visible = Properties.Settings.Default.ShowIcon; - Program.HackerWindow.ProcessProvider.Interval = Properties.Settings.Default.RefreshInterval; - Program.HackerWindow.ServiceProvider.Interval = Properties.Settings.Default.RefreshInterval; - Program.HackerWindow.NetworkProvider.Interval = Properties.Settings.Default.RefreshInterval; - Properties.Settings.Default.HighlightingDuration = (int)textHighlightingDuration.Value; Properties.Settings.Default.ColorNew = colorNewProcesses.Color; Properties.Settings.Default.ColorRemoved = colorRemovedProcesses.Color; @@ -302,12 +348,11 @@ namespace ProcessHacker Properties.Settings.Default.PlotterIOROColor = colorIORO.Color; Properties.Settings.Default.PlotterIOWColor = colorIOW.Color; - // apply the settings immediately if we can - HighlightingContext.HighlightingDuration = Properties.Settings.Default.HighlightingDuration; - HighlightingContext.Colors[ListViewItemState.New] = Properties.Settings.Default.ColorNew; - HighlightingContext.Colors[ListViewItemState.Removed] = Properties.Settings.Default.ColorRemoved; - TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.New] = Properties.Settings.Default.ColorNew; - TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.Removed] = Properties.Settings.Default.ColorRemoved; + Properties.Settings.Default.DbgHelpPath = textDbghelpPath.Text; + Properties.Settings.Default.DbgHelpSearchPath = textSearchPath.Text; + Properties.Settings.Default.DbgHelpUndecorate = checkUndecorate.Checked; + + Properties.Settings.Default.Save(); if (checkReplaceTaskManager.Enabled) { @@ -339,15 +384,26 @@ namespace ProcessHacker "Process Hacker", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + } - try - { - Properties.Settings.Default.DbgHelpPath = textDbghelpPath.Text; - Properties.Settings.Default.DbgHelpSearchPath = textSearchPath.Text; - Properties.Settings.Default.DbgHelpUndecorate = checkUndecorate.Checked; - } - catch - { } + private void ApplySettings() + { + Program.ImposterNames = new System.Collections.Specialized.StringCollection(); + + foreach (string s in Properties.Settings.Default.ImposterNames.Split(',')) + Program.ImposterNames.Add(s.Trim()); + + Program.HackerWindow.NotifyIcon.Visible = Properties.Settings.Default.ShowIcon; + Program.HackerWindow.ProcessProvider.Interval = Properties.Settings.Default.RefreshInterval; + Program.HackerWindow.ServiceProvider.Interval = Properties.Settings.Default.RefreshInterval; + Program.HackerWindow.NetworkProvider.Interval = Properties.Settings.Default.RefreshInterval; + + HighlightingContext.HighlightingDuration = Properties.Settings.Default.HighlightingDuration; + HighlightingContext.Colors[ListViewItemState.New] = Properties.Settings.Default.ColorNew; + HighlightingContext.Colors[ListViewItemState.Removed] = Properties.Settings.Default.ColorRemoved; + + TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.New] = Properties.Settings.Default.ColorNew; + TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.Removed] = Properties.Settings.Default.ColorRemoved; Program.HackerWindow.ProcessProvider.Interval = Properties.Settings.Default.RefreshInterval; Program.HackerWindow.ServiceProvider.Interval = Properties.Settings.Default.RefreshInterval; @@ -355,23 +411,21 @@ namespace ProcessHacker Program.SharedThreadProvider.Interval = Properties.Settings.Default.RefreshInterval; Program.SecondarySharedThreadProvider.Interval = Properties.Settings.Default.RefreshInterval; - Properties.Settings.Default.Save(); + Program.HackerWindow.ProcessTree.RefreshItems(); + Program.ApplyFont(Properties.Settings.Default.Font); if (_oldDbghelp != textDbghelpPath.Text) MessageBox.Show("One or more options you have changed require a restart of Process Hacker.", "Process Hacker", MessageBoxButtons.OK, MessageBoxIcon.Information); } - private void ApplySettings() - { - this.SaveSettings(); - Program.HackerWindow.ProcessTree.RefreshItems(); - Program.ApplyFont(Properties.Settings.Default.Font); - } - private void buttonOK_Click(object sender, EventArgs e) { - this.ApplySettings(); + this.SaveSettings(); + + if (!_dontApply) + this.ApplySettings(); + this.Close(); } @@ -411,17 +465,35 @@ namespace ProcessHacker { _font = fd.Font; buttonFont.Font = _font; + this.EnableApplyButton(); } } private void buttonChangeReplaceTaskManager_Click(object sender, EventArgs e) { - Program.StartProcessHackerAdmin("-o", () => + this.SaveSettings(); + if (!_dontApply) + this.ApplySettings(); + buttonApply.Enabled = false; + + string args = "-o -hwnd " + this.Handle.ToString() + + " -rect " + this.Location.X.ToString() + "," + this.Location.Y.ToString() + "," + + this.Size.Width.ToString() + "," + this.Size.Height.ToString(); + + Thread t = new Thread(() => { - this.SaveSettings(); - Program.HackerWindow.NotifyIcon.Visible = false; - Win32.ExitProcess(0); - }, this.Handle); + Program.StartProcessHackerAdminWait(args, this.Handle, 0xffffffff); + + this.BeginInvoke(new MethodInvoker(() => + { + Properties.Settings.Default.Reload(); + this.LoadSettings(); + this.ApplySettings(); + buttonApply.Enabled = false; + })); + }); + + t.Start(); } private void buttonEnableAll_Click(object sender, EventArgs e) @@ -446,5 +518,13 @@ namespace ProcessHacker if (ofd.ShowDialog() == DialogResult.OK) textDbghelpPath.Text = ofd.FileName; } + + private void buttonApply_Click(object sender, EventArgs e) + { + this.SaveSettings(); + this.ApplySettings(); + buttonApply.Enabled = false; + buttonOK.Select(); + } } } diff --git a/trunk/ProcessHacker/Forms/OptionsWindow.resx b/trunk/ProcessHacker/Forms/OptionsWindow.resx index 35956e64b..fb4813b39 100644 --- a/trunk/ProcessHacker/Forms/OptionsWindow.resx +++ b/trunk/ProcessHacker/Forms/OptionsWindow.resx @@ -120,7 +120,4 @@ 17, 17 - - 17, 17 - \ No newline at end of file diff --git a/trunk/ProcessHacker/Forms/ResultsWindow.cs b/trunk/ProcessHacker/Forms/ResultsWindow.cs index af5473588..b0926a634 100644 --- a/trunk/ProcessHacker/Forms/ResultsWindow.cs +++ b/trunk/ProcessHacker/Forms/ResultsWindow.cs @@ -27,6 +27,7 @@ using System.Threading; using System.Windows.Forms; using System.Collections.Generic; using ProcessHacker.UI; +using System.Drawing; namespace ProcessHacker { @@ -149,22 +150,16 @@ namespace ProcessHacker _so.Type = type; SearchWindow sw = new SearchWindow(_pid, _so); - System.Drawing.Rectangle workingArea = Screen.GetWorkingArea(sw); sw.StartPosition = FormStartPosition.Manual; sw.Location = new System.Drawing.Point( location.X + (size.Width - sw.Width) / 2, location.Y + (size.Height - sw.Height) / 2); - if (sw.Location.X < workingArea.Left) - sw.Location = new System.Drawing.Point(workingArea.Left, sw.Location.Y); - if (sw.Location.Y < workingArea.Top) - sw.Location = new System.Drawing.Point(sw.Location.X, workingArea.Top); + Rectangle newRect = Misc.FitRectangle(new Rectangle(sw.Location, sw.Size), Screen.GetWorkingArea(sw)); - if (sw.Location.X + sw.Size.Width > workingArea.Width) - sw.Location = new System.Drawing.Point(workingArea.Width - sw.Size.Width, sw.Location.Y); - if (sw.Location.Y + sw.Size.Height > workingArea.Height) - sw.Location = new System.Drawing.Point(sw.Location.X, workingArea.Height - sw.Size.Height); + sw.Location = newRect.Location; + sw.Size = newRect.Size; if ((dr = sw.ShowDialog()) == DialogResult.OK) { diff --git a/trunk/ProcessHacker/ProcessHacker.csproj b/trunk/ProcessHacker/ProcessHacker.csproj index ae5b4ec11..319782d05 100644 --- a/trunk/ProcessHacker/ProcessHacker.csproj +++ b/trunk/ProcessHacker/ProcessHacker.csproj @@ -586,6 +586,7 @@ VirtualProtectWindow.cs + diff --git a/trunk/ProcessHacker/Program/ExtendedCmd.cs b/trunk/ProcessHacker/Program/ExtendedCmd.cs index 666fe4799..565fa216c 100644 --- a/trunk/ProcessHacker/Program/ExtendedCmd.cs +++ b/trunk/ProcessHacker/Program/ExtendedCmd.cs @@ -53,21 +53,6 @@ namespace ProcessHacker } } - public class WindowFromHWnd : IWin32Window - { - private IntPtr _handle; - - public WindowFromHWnd(IntPtr handle) - { - _handle = handle; - } - - public IntPtr Handle - { - get { return _handle; } - } - } - public static void Run(IDictionary args) { ThemingScope.Activate(); @@ -87,10 +72,10 @@ namespace ProcessHacker string action = args["-action"].ToLower(); - WindowFromHWnd window = new WindowFromHWnd(IntPtr.Zero); + WindowFromHandle window = new WindowFromHandle(IntPtr.Zero); if (args.ContainsKey("-hwnd")) - window = new WindowFromHWnd(new IntPtr(int.Parse(args["-hwnd"]))); + window = new WindowFromHandle(new IntPtr(int.Parse(args["-hwnd"]))); try { diff --git a/trunk/ProcessHacker/Program/Program.cs b/trunk/ProcessHacker/Program/Program.cs index ffc1e3364..931cf3255 100644 --- a/trunk/ProcessHacker/Program/Program.cs +++ b/trunk/ProcessHacker/Program/Program.cs @@ -27,6 +27,7 @@ using System.Security.Principal; using System.Threading; using System.Windows.Forms; using ProcessHacker.Components; +using ProcessHacker.UI; namespace ProcessHacker { @@ -90,7 +91,6 @@ namespace ProcessHacker public static bool Aggressive = false; public static bool StartHidden = false; public static bool StartVisible = false; - public static bool ShowOptions = false; public static string SelectTab = "Processes"; public static Win32.TOKEN_ELEVATION_TYPE ElevationType; public static KProcessHacker KPH; @@ -129,7 +129,9 @@ namespace ProcessHacker // In case the settings file is corrupt PH won't crash here - it will be dealt with later. try { - if (Properties.Settings.Default.AllowOnlyOneInstance && !pArgs.ContainsKey("-e")) + if (Properties.Settings.Default.AllowOnlyOneInstance && + !(pArgs.ContainsKey("-e") || pArgs.ContainsKey("-o")) + ) CheckForPreviousInstance(); } catch @@ -252,13 +254,6 @@ namespace ProcessHacker { } { - if (pArgs.ContainsKey("-m")) - StartHidden = true; - if (pArgs.ContainsKey("-v")) - StartVisible = true; - if (pArgs.ContainsKey("-o")) - ShowOptions = true; - if (pArgs.ContainsKey("-a")) { Aggressive = true; @@ -271,18 +266,6 @@ namespace ProcessHacker { } } - if (pArgs.ContainsKey("")) - if (pArgs[""].Replace("\"", "").Trim().ToLower().EndsWith("taskmgr.exe")) - StartVisible = true; - - if (pArgs.ContainsKey("-t")) - { - if (pArgs["-t"] == "0") - SelectTab = "Processes"; - else if (pArgs["-t"] == "1") - SelectTab = "Services"; - } - if (pArgs.ContainsKey("-e")) { try @@ -296,6 +279,51 @@ namespace ProcessHacker return; } + + if (pArgs.ContainsKey("-o")) + { + OptionsWindow options = new OptionsWindow(true) + { + StartPosition = FormStartPosition.CenterScreen + }; + IWin32Window window; + + if (pArgs.ContainsKey("-hwnd")) + window = new WindowFromHandle(new IntPtr(int.Parse(pArgs["-hwnd"]))); + else + window = new WindowFromHandle(IntPtr.Zero); + + if (pArgs.ContainsKey("-rect")) + { + Rectangle rect = Misc.RectangleFromString(pArgs["-rect"]); + + options.Location = new Point(rect.X + 20, rect.Y + 20); + options.StartPosition = FormStartPosition.Manual; + } + + options.SelectedTab = options.TabPages["tabAdvanced"]; + options.Show(window); + Application.Run(options); + + return; + } + + if (pArgs.ContainsKey("")) + if (pArgs[""].Replace("\"", "").Trim().ToLower().EndsWith("taskmgr.exe")) + StartVisible = true; + + if (pArgs.ContainsKey("-m")) + StartHidden = true; + if (pArgs.ContainsKey("-v")) + StartVisible = true; + + if (pArgs.ContainsKey("-t")) + { + if (pArgs["-t"] == "0") + SelectTab = "Processes"; + else if (pArgs["-t"] == "1") + SelectTab = "Services"; + } } #if DEBUG @@ -397,6 +425,11 @@ namespace ProcessHacker } public static Win32.WaitResult StartProcessHackerAdminWait(string args, IntPtr hWnd, uint timeout) + { + return StartProcessHackerAdminWait(args, null, hWnd, timeout); + } + + public static Win32.WaitResult StartProcessHackerAdminWait(string args, MethodInvoker successAction, IntPtr hWnd, uint timeout) { Win32.SHELLEXECUTEINFO info = new Win32.SHELLEXECUTEINFO(); @@ -410,6 +443,9 @@ namespace ProcessHacker if (Win32.ShellExecuteEx(ref info)) { + if (successAction != null) + successAction(); + var result = Win32.WaitForSingleObject(info.hProcess, timeout); Win32.CloseHandle(info.hProcess); diff --git a/trunk/ProcessHacker/UI/WindowFromHandle.cs b/trunk/ProcessHacker/UI/WindowFromHandle.cs new file mode 100644 index 000000000..424e3a9f9 --- /dev/null +++ b/trunk/ProcessHacker/UI/WindowFromHandle.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace ProcessHacker.UI +{ + public class WindowFromHandle : IWin32Window + { + private IntPtr _handle; + + public WindowFromHandle(IntPtr handle) + { + _handle = handle; + } + + public IntPtr Handle + { + get { return _handle; } + } + } +}