How to launch Windows' RegEdit with certain path?
Asked Answered
S

16

49

How do I launch Windows' RegEdit with certain path located, like "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0", so I don't have to do the clicking?

What's the command line argument to do this? Or is there a place to find the explanation of RegEdit's switches?

Shame answered 26/9, 2008 at 0:55 Comment(1)
As Chris mentions, RegJump will do the trick. Also, if you find yourself jumping back and forth between several different paths, don't forget that you can set "Favorites" in Regedit. It's quite convenient, and you won't need a separate desktop icon for each one (as you might with RegJump).Lesko
A
31

There's a program called RegJump, by Mark Russinovich, that does just what you want. It'll launch regedit and move it to the key you want from the command line.

RegJump uses (or at least used to) use the same regedit window on each invoke, so if you want multiple regedit sessions open, you'll still have to do things the old fashioned way for all but the one RegJump has adopted. A minor caveat, but one to keep note of, anyway.

Accentor answered 26/9, 2008 at 1:5 Comment(3)
As Matt Dillard pointed out in another answer here, there's also Favorites in regedit, so you can quickly jump to different keys of your choice within regedit itself.Accentor
For Windows Vista/7/8 users: you might want to install elevate, add it to your PATH and then issue elevate regjump <path> if you plan to use it from your command line: superuser.com/a/42647/97570Princessprinceton
If you don't want to install RegJump, try @byron-persino's answer instead. It's more light-weight and does not require any third-party software.Cleodal
S
36

Use the following batch file (add to filename.bat):

REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Veritas\NetBackup\CurrentVersion\Config /f
START regedit

to replace:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Veritas\NetBackup\CurrentVersion\Config

with your registry path.

Scrimpy answered 20/9, 2012 at 15:33 Comment(5)
Best answer. Remembering that you must launch cmd with admin privileges to make second command function, or you can add & between the two commands and execute.Junitajunius
i think this answer should be set as the correct one as it dont need any software to be downloaded.Primogeniture
To have a script you can run, drop this in a .bat file: @echo off set /p regPath="Open regedit at path: " REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d "%regPath%" /f START regeditRosenkranz
@MattMiller Thanks for the script. if anyone is curious, the newlines are meant to be at "@echo", "set", "REG ADD" and "START". This works for me, but RegJump did not.Robison
Brilliant! Best answer. Thanks!Stokowski
A
31

There's a program called RegJump, by Mark Russinovich, that does just what you want. It'll launch regedit and move it to the key you want from the command line.

RegJump uses (or at least used to) use the same regedit window on each invoke, so if you want multiple regedit sessions open, you'll still have to do things the old fashioned way for all but the one RegJump has adopted. A minor caveat, but one to keep note of, anyway.

Accentor answered 26/9, 2008 at 1:5 Comment(3)
As Matt Dillard pointed out in another answer here, there's also Favorites in regedit, so you can quickly jump to different keys of your choice within regedit itself.Accentor
For Windows Vista/7/8 users: you might want to install elevate, add it to your PATH and then issue elevate regjump <path> if you plan to use it from your command line: superuser.com/a/42647/97570Princessprinceton
If you don't want to install RegJump, try @byron-persino's answer instead. It's more light-weight and does not require any third-party software.Cleodal
O
5

From http://windowsxp.mvps.org/jumpreg.htm (I have not tried any of these):

When you start Regedit, it automatically opens the last key that was viewed. (Registry Editor in Windows XP saves the last viewed registry key in a separate location). If you wish to jump to a particular registry key directly without navigating the paths manually, you may use any of these methods / tools.

Option 1
Using a VBScript: Copy these lines to a Notepad document as save as registry.vbs

'Launches Registry Editor with the chosen branch open automatically
'Author  : Ramesh Srinivasan
'Website: http://windowsxp.mvps.org

Set WshShell = CreateObject("WScript.Shell")
Dim MyKey
MyKey = Inputbox("Type the Registry path")
MyKey = "My Computer\" & MyKey
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Lastkey",MyKey,"REG_SZ"
WshShell.Run "regedit", 1,True
Set WshShell = Nothing

Double-click Registry.vbs and then type the full registry path which you want to open.

Example: HKEY_CLASSES_ROOT\.MP3

Limitation: The above method does not help if Regedit is already open.

Note: For Windows 7, you need to replace the line MyKey = "My Computer\" & MyKey with MyKey = "Computer\" & MyKey (remove the string My). For a German Windows XP the string "My Computer\" must be replaced by "Arbeitsplatz\".

Option 2
Regjump from Sysinternals.com

This little command-line applet takes a registry path and makes Regedit open to that path. It accepts root keys in standard (e.g. HKEY_LOCAL_MACHINE) and abbreviated form (e.g. HKLM).

Usage: regjump [path]

Example: C:\Regjump HKEY_CLASSES_ROOT\.mp3

Option 3
12Ghosts JumpReg from 12ghosts.com

Jump to registry keys from a tray icon! This is a surprisingly useful tool. You can manage and directly jump to frequently accessed registry keys. Unlimited list size, jump to keys and values, get current key with one click, jump to key in clipboard, jump to same in key in HKCU or HKLM. Manage and sort keys with comments in an easy-to-use tray icon menu. Create shortcuts for registry keys.

Orly answered 26/9, 2008 at 1:10 Comment(0)
S
5

Here is one more batch file solution with several enhancements in comparison to the other batch solutions posted here.

It sets also string value LastKey updated by Regedit itself on every exit to show after start the same key as on last exit.

@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "RootName=Computer"
set "RegKey=%~1"
if defined RegKey goto PrepareKey

echo/
echo Please enter the path of the registry key to open.
echo/
set "RegKey="
set /P "RegKey=Key path: "

rem Exit batch file without starting Regedit if nothing entered by user.
if not defined RegKey goto EndBatch

:PrepareKey
rem Remove double quotes and square brackets from entered key path.
set "RegKey=%RegKey:"=%"
if not defined RegKey goto EndBatch
set "RegKey=%RegKey:[=%"
if not defined RegKey goto EndBatch
set "RegKey=%RegKey:]=%"
if not defined RegKey goto EndBatch

rem Replace hive name abbreviation by appropriate long name.
set "Abbreviation=%RegKey:~0,4%"
if /I "%Abbreviation%" == "HKCC" set "RegKey=HKEY_CURRENT_CONFIG%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKCR" set "RegKey=HKEY_CLASSES_ROOT%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKCU" set "RegKey=HKEY_CURRENT_USER%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKLM" set "RegKey=HKEY_LOCAL_MACHINE%RegKey:~4%" & goto GetRootName
if /I "%RegKey:~0,3%" == "HKU" set "RegKey=HKEY_USERS%RegKey:~3%"

:GetRootName
rem Try to determine automatically name of registry root.
if not exist %SystemRoot%\Sysnative\reg.exe (set "RegEXE=%SystemRoot%\System32\reg.exe") else set "RegEXE=%SystemRoot%\Sysnative\reg.exe"
for /F "skip=2 tokens=1,2*" %%K in ('%RegEXE% QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey"') do if /I "%%K" == "LastKey" for /F "delims=\" %%N in ("%%M") do set "RootName=%%N"

rem Is Regedit already running?
%SystemRoot%\System32\tasklist.exe /NH /FI "IMAGENAME eq regedit.exe" | %SystemRoot%\System32\findstr.exe /B /I /L regedit.exe >nul || goto SetRegPath

echo/
echo Regedit is already running. Path can be set only when Regedit is not running.
echo/
set "UserChoice=N"
set /P "UserChoice=Terminate Regedit (y/N): "
if /I "%UserChoice:"=%" == "y" %SystemRoot%\System32\taskkill.exe /IM regedit.exe >nul 2>nul & goto SetRegPath
echo Switch to running instance of Regedit without setting entered path.
goto StartRegedit

:SetRegPath
rem Add this key as last key to registry for Regedit.
%RegEXE% ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "%RootName%\%RegKey%" /f >nul 2>nul

:StartRegedit
if not exist %SystemRoot%\Sysnative\cmd.exe (start %SystemRoot%\regedit.exe) else %SystemRoot%\Sysnative\cmd.exe /D /C start %SystemRoot%\regedit.exe

:EndBatch
endlocal

The enhancements are:

  1. Registry path can be passed also as command line parameter to the batch script.

  2. Registry path can be entered or pasted with or without surrounding double quotes.

  3. Registry path can be entered or pasted or passed as parameter with or without surrounding square brackets.

  4. Registry path can be entered or pasted or passed as parameter also with an abbreviated hive name (HKCC, HKCU, HKCR, HKLM, HKU).

  5. Batch script checks for already running Regedit as registry key is not shown when starting Regedit while Regedit is already running. The batch user is asked if running instance should be terminated to restart it for showing entered registry path. If the batch user chooses not to terminate all instances of Regedit, Regedit is started without setting entered path resulting (usually) in just getting Regedit window to foreground.

  6. The batch file tries to automatically get name of registry root which is on English Windows XP My Computer, on German Windows XP, Arbeitsplatz, and on Windows 7 and newer Windows just Computer. This could fail if the value LastKey of Regedit is missing or empty in registry. Please set the right root name in third line of the batch code for this case.

  7. The batch file runs on 64-bit Windows always Regedit in 64-bit execution environment even on batch file being processed by 32-bit %SystemRoot%\SysWOW64\cmd.exe on 64-bit Windows which is important for registry keys affected by WOW64.

Sha answered 14/3, 2015 at 15:56 Comment(2)
I performed command with "Computer" as root although my registry root was "Computador" (pt-br), and it worked well, regardless of the root name...Junitajunius
@Junitajunius Nice to know that this batch file works also for Brazil and that it could find out Computador as root name by itself using the code under label GetRootName and explained briefly in point 6.Sha
A
4

I'd also like to note that you can view and edit the registry from within PowerShell. Launch it, and use set-location to open the registry location of your choice. The short name of an HKEY is used like a drive letter in the file system (so to go to HKEY_LOCAL_MACHINE\Software, you'd say: set-location hklm:\Software).

More details about managing the registry in PowerShell can be found by typing get-help Registry at the PowerShell command prompt.

Accentor answered 26/9, 2008 at 1:15 Comment(0)
P
3

I thought this C# solution might help:

By making use of an earlier suggestion, we can trick RegEdit into opening the key we want even though we can't pass the key as a parameter.

In this example, a menu option of "Registry Settings" opens RegEdit to the node for the program that called it.

Program's form:

    private void registrySettingsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string path = string.Format(@"Computer\HKEY_CURRENT_USER\Software\{0}\{1}\",
                                    Application.CompanyName, Application.ProductName);

        MyCommonFunctions.Registry.OpenToKey(path);

    }

MyCommonFunctions.Registry

    /// <summary>Opens RegEdit to the provided key
    /// <para><example>@"Computer\HKEY_CURRENT_USER\Software\MyCompanyName\MyProgramName\"</example></para>
    /// </summary>
    /// <param name="FullKeyPath"></param>
    public static void OpenToKey(string FullKeyPath)
    {
        RegistryKey rKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit", true);
        rKey.SetValue("LastKey",FullKeyPath);

        Process.Start("regedit.exe");
    }

Of course, you could put it all in one method of the form, but I like reusablity.

Purvis answered 19/1, 2013 at 18:47 Comment(0)
P
3

Copy the below text and save it as a batch file and run

@ECHO OFF
SET /P "showkey=Please enter the path of the registry key: "
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "%showkey%" /f
start "" regedit

Input the path of the registry key you wish to open when the batch file prompts for it, and press Enter. Regedit opens to the key defined in that value.

Perrault answered 27/3, 2014 at 19:20 Comment(0)
M
2

Here is a simple PowerShell function based off of this answer above https://mcmap.net/q/350777/-how-to-launch-windows-39-regedit-with-certain-path

function jumpReg ($registryPath)
{
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" `
                     -Name "LastKey" `
                     -Value $registryPath `
                     -PropertyType String `
                     -Force

    regedit
}

jumpReg ("Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run") | Out-Null

The answer above doesn't actually explain very well what it does. When you close RegEdit, it saves your last known position in HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit, so this merely replaces the last known position with where you want to jump, then opens it.

Mraz answered 11/4, 2017 at 17:35 Comment(0)
A
2

If the main goal is just to avoid "the clicking", then in Windows 10 you can just type or paste the destination path into RegEdit's address bar and hit enter.

RegEdit address bar

The Computer\ prefix here is added automatically. It will also work if you simply type or paste a path starting with e.g. HKEY_CURRENT_USER\....

Alessandro answered 21/9, 2020 at 13:58 Comment(0)
J
1

Create a BAT file using clipboard.exe and regjump.exe to jump to the key in the clipboard:

clipboard.exe > "%~dp0clipdata.txt"
set /p clipdata=input < "%~dp0clipdata.txt"
regjump.exe %clipdata%

( %~dp0 means "the path to the BAT file" )

Jeana answered 3/10, 2012 at 21:12 Comment(1)
'clipboard' is not recognized as an internal or external command, operable program or batch file.Adequate
A
1

Building on lionkingrafiki's answer, here's a more robust solution that will accept a reg key path as an argument and will automatically translate HKLM to HKEY_LOCAL_MACHINE or similar as needed. If no argument, the script checks the clipboard using the htmlfile COM object invoked by a JScript hybrid chimera. The copied data will be split and tokenized, so it doesn't matter if it's not trimmed or even among an entire paragraph of copied dirt. And finally, the key's existence is verified before LastKey is modified. Key paths containing spaces must be within double quotes.

@if (@CodeSection == @Batch) @then
:: regjump.bat
@echo off & setlocal & goto main

:usage
echo Usage:
echo   * %~nx0 regkey
echo   * %~nx0 with no args will search the clipboard for a reg key
goto :EOF

:main
rem // ensure variables are unset
for %%I in (hive query regpath) do set "%%I="

rem // if argument, try navigating to argument.  Else find key in clipboard.
if not "%~1"=="" (set "query=%~1") else (
    for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0"') do (
        set "query=%%~I"
    )
)

if not defined query (
    echo No registry key was found in the clipboard.
    goto usage
)

rem // convert HKLM to HKEY_LOCAL_MACHINE, etc. while checking key exists
for /f "delims=\" %%I in ('reg query "%query%" 2^>NUL') do (
    set "hive=%%~I" & goto next
)

:next
if not defined hive (
    echo %query% not found in the registry
    goto usage
)

rem // normalize query, expanding HKLM, HKCU, etc.
for /f "tokens=1* delims=\" %%I in ("%query%") do set "regpath=%hive%\%%~J"
if "%regpath:~-1%"=="\" set "regpath=%regpath:~0,-1%"

rem // https://mcmap.net/q/350777/-how-to-launch-windows-39-regedit-with-certain-path
>NUL 2>NUL (
    REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit"^
        /v "LastKey" /d "%regpath%" /f
)

echo %regpath%

start "" regedit
goto :EOF

@end // begin JScript hybrid chimera
// https://mcmap.net/q/271012/-access-clipboard-in-windows-batch-file
var clip = WSH.CreateObject('htmlfile').parentWindow.clipboardData.getData('text');

clip.replace(/"[^"]+"|\S+/g, function($0) {
    if (/^\"?(HK[CLU]|HKEY_)/i.test($0)) {
        WSH.Echo($0);
        WSH.Quit(0);
    }
});
Adequate answered 16/2, 2016 at 0:1 Comment(0)
C
1

PowerShell way:

Function Jump-Registry([string]$registryPath) {
  $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", $true)

  if ((Test-Path ('registry::' + $registryPath) -PathType Container -ea si) -and ![System.String]::IsNullOrEmpty($key)) 
  {
    $key.SetValue("LastKey", $registryPath, [Microsoft.Win32.RegistryValueKind]::String)
    $key.Close()
    [void]([System.Diagnostics.Process]::Start("regedit.exe"))
  } else {
    Write-Error "[ $registryPath ]   may not exist. Please check the path and try again"
  }
}
Jump-Registry "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"

Or:

Jump-Registry "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
Cloudy answered 12/4, 2023 at 1:59 Comment(0)
H
0

This seems horribly out of date, but Registration Info Editor (REGEDIT) Command-Line Switches claims that it doesn't support this.

Haircut answered 26/9, 2008 at 1:4 Comment(1)
That's a whole different regedit... What we call regedit now is not the same as the Win3.x regedit. support.microsoft.com/kb/141377/en-usAccentor
P
0

You can make it appear like regedit does this behaviour by creating a batch file (from the submissions already given) but call it regedit.bat and put it in the C:\WINDOWS\system32 folder. (you may want it to skip editting the lastkey in the registry if no command line args are given, so "regedit" on its own works as regedit always did) Then "regedit HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0" will do what you want.

This uses the fact that the order in PATH is usually C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem; etc

Prudenceprudent answered 18/3, 2016 at 16:48 Comment(0)
A
0

PowerShell code:

# key you want to open
$regKey = "Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\IntuneManagementExtension\Policies\"
# set starting location for regedit
Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" "LastKey" $regKey
# open regedit (-m allows multiple regedit windows)
regedit.exe -m
Adenoidal answered 8/4, 2021 at 7:28 Comment(0)
O
0

This is the best answer overall, as it's quick, simple and there's no need to install any program.
By Byron Persino, improved by Matt Miller. (Many thanks to both of them!)

I'm rewording more correctly and clearly to help other readers like me, as I had a lot of trouble getting it clear and make it working.

Make a .bat file, eg. 'GoToRegEditPath.bat' , write the following code inside and save it:

CODE:

@echo off
set /p regPath="Open regedit at path: " 
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d "%regPath%" /f
START regedit
exit
:: source: 
https://mcmap.net/q/350777/-how-to-launch-windows-39-regedit-with-certain-path?answertab=modifieddesc#tab-top

Maybe this .bat use must "Run as Administrator"
To use it, Just run it and paste (R-Click) in it the copied RegEdit Path.

Tip: if R-click does not work inside command prompt:
R-click on title bar > Properties > check both under "Edit Options"

Ozonide answered 1/9, 2022 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.