[译]快速Regedit导航
By robot-v1.0
本文链接 https://www.kyfws.com/applications/quick-regedit-navigation-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1537 个词[译]快速Regedit导航
原文地址:https://www.codeproject.com/Articles/12554/Quick-Regedit-Navigation
原文作者:David Crow
译文由本站 robot-v1.0 翻译
前言
A tool to quickly navigate to a particular key/value using Regedit.
使用Regedit快速导航到特定键/值的工具.
介绍(Introduction)
您有多少次在CP或与此相关的互联网上的任何地方看到过一次帖子,其中包含对长注册表项的引用,并且认为如果不使用该注册表项就直接使用该注册表项将很有用.将其输入regedit?我想我有解决办法.(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)
要找到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
值.接下来,我们需要显示Regedit的窗口并将其置于前台.(value. Next, we need to show Regedit’s window and bring it to the foreground.)
pWndRegeditMain->ShowWindow(SW_SHOW);
pWndRegeditMain->SetForegroundWindow();
树视图(The TreeView)
由于Regedit维护最后访问的密钥(请参阅(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.)
ListView(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(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.)
一旦Regedit完成向下导航到所需的键,您应该具有类似于以下内容的内容:(Once Regedit has finished navigating down to the desired key, you should have something that resembles the following:)
附加功能(Extras)
我碰巧喜欢的一个功能是Regedit自动选择上次访问的密钥.此项的名称存储在以下值中:(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(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey)
您可以通过删除对以下内容的写入权限来阻止Regedit维护最后访问的密钥:(You can keep Regedit from maintaining the last-accessed key by removing write permission to the) Regedit
键.但是,需要进行权衡.这样,您还将禁止Regedit更新(key. However, there is a tradeoff. By doing so, you’ll also be prohibiting Regedit from updating the) FindFlags
和(and) View
价值观.(values.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 Windows WinXP MFC Visual-Studio QA Dev 新闻 翻译