If you are addicted to various registry tweaks like I am, you probably work with the Registry Editor very often. Various websites related to tweaking instruct you to go to different registry keys. I would like to share my own way to jump to the desired registry key directly and skip manual navigation with the Registry Editor. This can be done with a simple VB script file without using third-party software. Click "Read more" if you are interested.
Overview
Since Windows 2000, the Registry Editor is able to remember the last opened key before you closed it. This data is stored at the following registry key:
HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit
The Last Key value is used by Windows to store the last used key.
As you can see, this is a per-user registry branch, so Windows stores the last used key for every user separately. It is possible to utilize this feature to directly jump to the key you need. Let me show how it can be done via Windows Scripting Host and VBScript.
The Implementation
The idea is to copy the full path of the desired registry key to the clipboard and replace the LastKey value with the copied value from the clipboard. When regedit.exe is started after doing this, it will open directly at the key you want.
How to fetch clipboard content with VBscript
The "htmlfile" ActiveX object is used to display HTML help and HTA files in Windows. It can be used to fetch clipboard content. It does not even require IE to be installed . The code is as follows:
set objHTA=createobject("htmlfile")
cClipBoard=objHTA.parentwindow.clipboarddata.getdata("text")
If clipboard content is text, it will be stored in ClipBoard variable. Simple, isn't it?
Directly opening Regedit at desired key
Since we now have the desired key in cClipboard, we have to write it into LastKey value metioned above. The code for that is:
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey", сClipBoard, "REG_SZ"
This code snippet is self-explanatory, so there is no need to comment it.
The final script looks like this:
Dim objHTA
Dim cClipBoard
Dim WshShell
set objHTA=createobject("htmlfile")
cClipBoard=objHTA.parentwindow.clipboarddata.getdata("text")
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey", cClipBoard, "REG_SZ"
WshShell.Run "regedit.exe -m"
Set objHTA = nothing
Set WshShell = nothing
Note that WshShell.Run "regedit.exe -m" line. It contains the undocumented "-m" switch, which allows you to run multiple instances of Regedit simultaneously.
I have saved this script as "RegNav.vbs" file and you can download it right now:
If opening Regedit is a very frequent task for you, then you can pin regnav.vbs to the taskbar. Create a new shortcut and type the following into the shortcut target text box:
wscript.exe d:\regnav.vbs
Don't forget to use the correct path to regnav.vbs.
Now right click on the shortcut file you have created and click "Pin to Taskbar" from the context menu. That's all.
P.S. How to test this script
- Select this text
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
- Press CTRL+C
- Click on regnav.vbs.
0 comments:
Post a Comment