How to launch Windows' RegEdit with certain path?

前端 未结 13 1033
盖世英雄少女心
盖世英雄少女心 2020-12-08 04:15

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 clic

相关标签:
13条回答
  • Here is one more batch file solution with several enhancements in comparison to the other batch solutions posted here.

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

    @echo off
    setlocal EnableDelayedExpansion
    set "RootName=Computer"
    
    if not "%~1"=="" (
        set "RegKey=%~1"
        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 "!RegKey!"=="" goto ExitBatch
    
    :PrepareKey
    rem Remove square brackets and double quotes from entered key path.
    set "RegKey=!RegKey:"=!"
    if "!RegKey!"=="" goto ExitBatch
    set "RegKey=!RegKey:[=!"
    if "!RegKey!"=="" goto ExitBatch
    set "RegKey=!RegKey:]=!"
    if "!RegKey!"=="" goto ExitBatch
    
    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.
    for /F "tokens=1,2*" %%K in ('%SystemRoot%\System32\reg.exe 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 | %SystemRoot%\System32\findstr.exe /B /I /L regedit.exe >nul
    if errorlevel 1 goto SetRegPath
    
    echo/
    echo Regedit is already running. Path can be set only when Regedit is not running.
    echo/
    set "Choice=N"
    set /P "Choice=Kill Regedit (y/N): "
    if /I "!Choice!"=="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.
    %SystemRoot%\System32\reg.exe add "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "%RootName%\%RegKey%" /f >nul 2>nul
    
    :StartRegedit
    start /B regedit.exe
    
    :ExitBatch
    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 running already. The batch user is asked if running instance should be killed to restart it for showing entered registry path. If the batch user chooses not to kill 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 just Computer. This could fail if the value LastKey of Regedit is missing or empty in registry. For this case please set the right root name in third line of the batch code.

    0 讨论(0)
  • 2020-12-08 04:40

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

    0 讨论(0)
  • 2020-12-08 04:43

    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.

    0 讨论(0)
  • 2020-12-08 04:47

    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.

    0 讨论(0)
  • 2020-12-08 04:50

    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.

    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\....

    0 讨论(0)
  • 2020-12-08 04:54

    Here is a simple PowerShell function based off of this answer above https://stackoverflow.com/a/12516008/1179573

    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.

    0 讨论(0)
提交回复
热议问题