diff --git a/trunk/CHANGELOG.txt b/trunk/CHANGELOG.txt index 1b8d7a68a..78136d291 100644 --- a/trunk/CHANGELOG.txt +++ b/trunk/CHANGELOG.txt @@ -6,6 +6,7 @@ Process Hacker * Better handle granted access display * Thread list is more responsive * Process exit notification (in the process window) is now instant + * Ability to open key handles in regedit * FIXED: * Properties menu item for handles was disabled most of the time * Handle names could not be viewed properly without KPH and diff --git a/trunk/ProcessHacker/Common/PhUtils.cs b/trunk/ProcessHacker/Common/PhUtils.cs index 666db1dd8..064208b18 100644 --- a/trunk/ProcessHacker/Common/PhUtils.cs +++ b/trunk/ProcessHacker/Common/PhUtils.cs @@ -22,13 +22,13 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Windows.Forms; using Aga.Controls.Tree; using ProcessHacker.Native; using ProcessHacker.Native.Api; using ProcessHacker.Native.Objects; using ProcessHacker.UI; -using System.Drawing; namespace ProcessHacker.Common { @@ -105,6 +105,53 @@ namespace ProcessHacker.Common return Color.White; } + public static void OpenKeyInRegedit(string keyName) + { + OpenKeyInRegedit(null, keyName); + } + + public static void OpenKeyInRegedit(IWin32Window window, string keyName) + { + string lastKey = keyName; + + // Expand the abbreviations. + if (lastKey.ToLowerInvariant().StartsWith("hkcu")) + lastKey = "HKEY_CURRENT_USER" + lastKey.Substring(4); + else if (lastKey.ToLowerInvariant().StartsWith("hku")) + lastKey = "HKEY_USERS" + lastKey.Substring(3); + else if (lastKey.ToLowerInvariant().StartsWith("hkcr")) + lastKey = "HKEY_CLASSES_ROOT" + lastKey.Substring(4); + else if (lastKey.ToLowerInvariant().StartsWith("hklm")) + lastKey = "HKEY_LOCAL_MACHINE" + lastKey.Substring(4); + + using (var regeditKey = + Microsoft.Win32.Registry.CurrentUser.OpenSubKey( + @"Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", + true + )) + { + if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista)) + regeditKey.SetValue("LastKey", "Computer\\" + lastKey); + else + regeditKey.SetValue("LastKey", lastKey); + } + + if (OSVersion.HasUac && Program.ElevationType == TokenElevationType.Limited) + { + Program.StartProgramAdmin( + Environment.SystemDirectory + "\\..\\regedit.exe", + "", + null, + ShowWindowType.Normal, + window != null ? window.Handle : IntPtr.Zero + ); + } + else + { + System.Diagnostics.Process.Start(Environment.SystemDirectory + "\\..\\regedit.exe"); + } + } + /// /// Selects all of the specified nodes. /// diff --git a/trunk/ProcessHacker/Components/HandleList.cs b/trunk/ProcessHacker/Components/HandleList.cs index 7eaf18372..59b4d9647 100644 --- a/trunk/ProcessHacker/Components/HandleList.cs +++ b/trunk/ProcessHacker/Components/HandleList.cs @@ -339,6 +339,7 @@ namespace ProcessHacker.Components // Objects with separate property windows: case "file": case "job": + case "key": case "token": case "process": { @@ -367,6 +368,18 @@ namespace ProcessHacker.Components (new JobWindow(JobObjectHandle.FromHandle(dupHandle))).ShowDialog(); } break; + case "key": + { + try + { + PhUtils.OpenKeyInRegedit(Form.ActiveForm, name); + } + catch (Exception ex) + { + PhUtils.ShowMessage("Error opening the registry editor", ex); + } + } + break; case "token": { (new TokenWindow(new RemoteTokenHandle(phandle,