Click here to Skip to main content
11,502,201 members (64,339 online)
Click here to Skip to main content

Quick Regedit Navigation

, 29 Dec 2005 62.8K 314 24
Rate this:
Please Sign up or sign in to vote.
A tool to quickly navigate to a particular key/value using Regedit.

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.

CWnd *pWndRegeditMain = CWnd::FindWindow(_T("RegEdit_RegEdit"), NULL);
if (NULL == pWndRegeditMain)
{
    rShellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    rShellExecuteInfo.fMask  = SEE_MASK_NOCLOSEPROCESS; 
    rShellExecuteInfo.lpVerb = _T("open"); 
    rShellExecuteInfo.lpFile = _T("regedit.exe"); 
    rShellExecuteInfo.nShow  = SW_SHOWNORMAL; 

    ShellExecuteEx(&rShellExecuteInfo);
    WaitForInputIdle(rShellExecuteInfo.hProcess, INFINITE);

    pWndRegeditMain = CWnd::FindWindow(_T("RegEdit_RegEdit"), NULL);
}

At this point, pWndRegeditMain should have a non-NULL value. Next, we need to show Regedit's window and bring it to the foreground.

pWndRegeditMain->ShowWindow(SW_SHOW);
pWndRegeditMain->SetForegroundWindow();

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:

key\ 
key\value

To separate the two, we use:

CString strRegistryPath(argv[1]);

// the path must begin with a backslash
if (strRegistryPath.Left(1) != _T('\\'))
    strRegistryPath = _T('\\') + strRegistryPath;

int nIndex       = strRegistryPath.ReverseFind(_T('\\'));
CString strValue = strRegistryPath.Mid(nIndex + 1);
strRegistryPath  = strRegistryPath.Left(nIndex);

Note that when a backslash character is encountered, we "send" a right arrow key instead.

for (nIndex = 0; nIndex < strRegistryPath.GetLength(); nIndex++)
{
    UINT uVirtualKey = strRegistryPath[nIndex];

    if (_T('\\') == uVirtualKey)  
        WndRegeditTreeview.SendMessage(WM_KEYDOWN, VK_RIGHT, 0);
    else
    {
        uVirtualKey = toupper(uVirtualKey);
        WndRegeditTreeview.SendMessage(WM_CHAR, uVirtualKey, 0);
    }
}

At this point, we should be at the desired key in the left pane.

The ListView

Now if a value was also specified, we must switch over to the list view and select it.

CWnd WndRegeditListview;
WndRegeditListview.Attach(FindWindowEx(pWndRegeditMain->GetSafeHwnd(), 
                                       NULL, _T("SysListView32"), NULL));
WndRegeditListview.SetForegroundWindow();
WndRegeditListview.SetFocus();

// have to wait for Regedit to update the listview
Sleep(1000); 

// select the value
WndRegeditListview.SendMessage(WM_KEYDOWN, VK_HOME, 0);

for (nIndex = 0; nIndex < strValue.GetLength(); nIndex++)
{
    UINT uVirtualKey = toupper(strValue[nIndex]);
    WndRegeditListview.SendMessage(WM_CHAR, uVirtualKey, 0);
}

Our value should now be selected. We can detach the temporary view objects and exit the program.

Usage

From a command prompt, simply type regeditgo followed by the desired key\value. If the key and/or value contains any spaces, you'll need to surround it with double quotes.

Once Regedit has finished navigating down to the desired key, you should have something that resembles the following:

Extras

A feature that I happen to like is Regedit's automatic selection of the last-accessed key. The name of this key is stored in the following value:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey

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.

A list of licenses authors might use can be found here

Share

About the Author

DavidCrow
Software Developer (Senior) Pinnacle Business Systems
United States United States

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

HTTP 404 - File not found
Internet Information Services

Comments and Discussions

 
Generalusing in commercial application Pin
myalias1234567828-Nov-06 13:04
membermyalias1234567828-Nov-06 13:04 
GeneralRe: using in commercial application Pin
DavidCrow29-Nov-06 2:28
memberDavidCrow29-Nov-06 2:28 
GeneralRe: using in commercial application Pin
myalias1234567829-Nov-06 6:37
membermyalias1234567829-Nov-06 6:37 
QuestionRe: using in commercial application Pin
DavidCrow29-Nov-06 6:59
memberDavidCrow29-Nov-06 6:59 
AnswerRe: using in commercial application Pin
myalias1234567812-Dec-06 13:40
membermyalias1234567812-Dec-06 13:40 
General! Like RegMon Pin
Synetech12-Aug-06 7:35
memberSynetech12-Aug-06 7:35 
GeneralAuto-Complete Pin
davedoc29-Dec-05 9:38
memberdavedoc29-Dec-05 9:38 
GeneralRe: Auto-Complete Pin
Mr.Prakash13-Jan-06 17:41
memberMr.Prakash13-Jan-06 17:41 
GeneralInteresting idea, but too much reliance on keystrokes Pin
HerbCSO29-Dec-05 8:53
memberHerbCSO29-Dec-05 8:53 
QuestionRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow29-Dec-05 10:00
memberDavidCrow29-Dec-05 10:00 
AnswerRe: Interesting idea, but too much reliance on keystrokes Pin
HerbCSO29-Dec-05 10:19
memberHerbCSO29-Dec-05 10:19 
I've just had (past experience) a lot of problems trying to automate UI's with keystrokes. It turns out that sometimmes other apps will pop into the foreground, thus taking the keystrokes out of the buffer, etc. I just don't like doing it anymore, that's all - call it a personal preference. ;]

--
Umm... what's a .sig? ;]
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow29-Dec-05 10:53
memberDavidCrow29-Dec-05 10:53 
AnswerRe: Interesting idea, but too much reliance on keystrokes Pin
Ivo Beltchev29-Dec-05 10:41
memberIvo Beltchev29-Dec-05 10:41 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow29-Dec-05 10:51
memberDavidCrow29-Dec-05 10:51 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
Ivo Beltchev29-Dec-05 11:02
memberIvo Beltchev29-Dec-05 11:02 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
hector santos29-Dec-05 23:28
memberhector santos29-Dec-05 23:28 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow1-Jan-06 9:08
memberDavidCrow1-Jan-06 9:08 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
JimmyRopes30-Dec-05 23:09
memberJimmyRopes30-Dec-05 23:09 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow3-Jan-06 2:57
memberDavidCrow3-Jan-06 2:57 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
JimmyRopes3-Jan-06 4:32
memberJimmyRopes3-Jan-06 4:32 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
Karim AM16-Jan-06 14:46
memberKarim AM16-Jan-06 14:46 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
JimmyRopes17-Jan-06 2:46
memberJimmyRopes17-Jan-06 2:46 
GeneralRe: Interesting idea, but too much reliance on keystrokes Pin
DavidCrow17-Jan-06 2:48
memberDavidCrow17-Jan-06 2:48 
GeneralCool idea :-) Pin
Nishant Sivakumar29-Dec-05 8:40
staffNishant Sivakumar29-Dec-05 8:40 
GeneralRe: Cool idea :-) Pin
Mr.Prakash13-Jan-06 17:43
memberMr.Prakash13-Jan-06 17:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 29 Dec 2005
Article Copyright 2005 by DavidCrow
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid