Introduction

How many times have you seen a post here at CP, or any place out on the Internet for that matter, that contained a reference to a long registry key, and thought how useful it would be if you could go straight to that key without having to type it into regedit? I think I have a solution.

Finding and Opening Regedit

To find Regedit's window, we search for and/or create the "RegEdit_RegEdit" window class.

The TreeView

Since Regedit maintains the last-accessed key (see Extras), we must ensure a known starting point: the root node. To do this, we simply "send" the left arrow key several dozen times.

CWnd WndRegeditTreeview;
WndRegeditTreeview.Attach(FindWindowEx(pWndRegeditMain->GetSafeHwnd(),
NULL, _T("SysTreeView32"), NULL));
WndRegeditTreeview.SetForegroundWindow();
WndRegeditTreeview.SetFocus();
// close it up so we have a known starting point
for (int nDepth = 0; nDepth < 30; nDepth++)
WndRegeditTreeview.SendMessage(WM_KEYDOWN, VK_LEFT, 0);

Now that we are at the root node, we can start our descent down to the desired key. The key, as far as this code is concerned, can be formed in one of two ways:

You can keep Regedit from maintaining the last-accessed key by removing write permission to the Regedit key. However, there is a tradeoff. By doing so, you'll also be prohibiting Regedit from updating the FindFlags and View values.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

When I passed it this key, for instance, HKEY_CURRENT_USER\Software\Adobe it would open up the key

HKEY_CURRENT_USER\Software... and select the default value. Also, there was no way of telling it whether there was a value being passed in or just a key. So what I did was the following. Fix the above problem and add a way to tell the program that it has a key. So the function now has the signature

int RegEditGo( LPCTSTR lpszRegistryPath, LPCTSTR hasValue )

So when I pass a key by the msdos prompt as follows

HKEY_CURRENT_USER\Software\Adobe value1

it will open regedit and select value1

whereas if I pass in

HKEY_CURRENT_USER\Software\Adobe

it will just open the above key and not select any value even the default.