【问题标题】:How to launch Windows' RegEdit with certain path?如何使用特定路径启动 Windows 的 RegEdit?
【发布时间】:2008-09-26 00:55:48
【问题描述】:

如何启动 Windows 的 RegEdit 并找到特定路径,例如“HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0”,这样我就不必点击了?

执行此操作的命令行参数是什么?或者有没有地方可以找到RegEdit的开关的解释?

【问题讨论】:

  • 正如 Chris 提到的,RegJump 可以解决问题。此外,如果您发现自己在几条不同的路径之间来回跳跃,请不要忘记您可以在 Regedit 中设置“收藏夹”。这非常方便,而且您不需要为每个单独的桌面图标(就像使用 RegJump 一样)。

标签: command-line regedit


【解决方案1】:

Mark Russinovich 有一个名为RegJump 的程序,它可以满足您的需求。它将启动 regedit 并将其从命令行移至您想要的键。

RegJump 使用(或至少曾经)在每次调用时使用相同的 regedit 窗口,因此,如果您希望打开多个 regedit 会话,您仍然需要为除 RegJump 采用的一种方法之外的所有方法进行操作.一个小警告,但无论如何都要注意。

【讨论】:

  • 正如 Matt Dillard 在此处的另一个答案中指出的那样,regedit 中也有收藏夹,因此您可以在 regedit 本身中快速跳转到您选择的不同键。
  • 对于 Windows Vista/7/8 用户:您可能想要安装 elevate,将其添加到您的 PATH,然后如果您打算从命令行使用它,请发出 elevate regjump <path>superuser.com/a/42647/97570
  • 如果您不想安装 RegJump,请尝试使用 @byron-persino 的 answer。它更轻巧,不需要任何第三方软件。
【解决方案2】:

使用以下批处理文件(添加到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

替换:

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

使用您的注册表路径。

【讨论】:

  • 最佳答案。请记住,您必须以管理员权限启动 cmd 才能使第二个命令起作用,或者您可以在两个命令之间添加 & 并执行。
  • 我认为这个答案应该设置为正确的,因为它不需要下载任何软件。
  • 要拥有可以运行的脚本,请将其放入 .bat 文件中:@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
  • @MattMiller 感谢您的脚本。如果有人好奇,换行符应该在“@echo”、“set”、“REG ADD”和“START”。这对我有用,但 RegJump 没有。
  • 太棒了!最佳答案。谢谢!
【解决方案3】:

来自http://windowsxp.mvps.org/jumpreg.htm(我没有尝试过任何这些):

当您启动 Regedit 时,它会自动打开上次查看的键。 (Windows XP 中的注册表编辑器将上次查看的注册表项保存在单独的位置)。如果您希望直接跳转到特定注册表项而不手动导航路径,您可以使用这些方法/工具中的任何一种。

选项 1
使用 VBScript:将这些行复制到记事本文档中,另存为 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

双击 Registry.vbs,然后键入要打开的完整注册表路径。

例如:HKEY_CLASSES_ROOT\.MP3

限制:如果Regedit已经打开,上述方法无效。

注意:对于 Windows 7,您需要将行 MyKey = "My Computer\" & MyKey 替换为 MyKey = "Computer\" & MyKey(删除字符串 My)。对于德语 Windows XP,字符串 "My Computer\" 必须替换为 "Arbeitsplatz\"

选项 2
从 Sysinternals.com 跳转

这个小命令行小程序采用注册表路径并使 Regedit 打开到该路径。它接受标准(例如 HKEY_LOCAL_MACHINE)和缩写形式(例如 HKLM)的根密钥。

用法:regjump [路径]

示例:C:\Regjump HKEY_CLASSES_ROOT\.mp3

选项 3
来自 12ghosts.com 的 12Ghosts JumpReg

从托盘图标跳转到注册表项!这是一个非常有用的工具。您可以管理并直接跳转到经常访问的注册表项。无限列表大小,跳转到键和值,一键获取当前键,跳转到剪贴板中的键,在 HKCU 或 HKLM 中跳转到相同的键。在易于使用的托盘图标菜单中使用 cmets 管理和排序键。为注册表项创建快捷方式。

【讨论】:

    【解决方案4】:

    我还想指出,您可以在 PowerShell 中查看和编辑注册表。启动它,然后使用 set-location 打开您选择的注册表位置。 HKEY 的短名称用作文件系统中的驱动器号(因此要转到 HKEY_LOCAL_MACHINE\Software,您会说:set-location hklm:\Software)。

    可以通过在 PowerShell 命令提示符下键入 get-help Registry 找到有关在 PowerShell 中管理注册表的更多详细信息。

    【讨论】:

      【解决方案5】:

      与此处发布的其他批处理解决方案相比,这里是另一种批处理文件解决方案,具有多项增强功能。

      它还设置字符串值LastKey 在每次退出时由 Regedit 自己更新,以便在启动后显示与上次退出时相同的键。

      @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
      

      增强功能是:

      1. 注册表路径也可以作为命令行参数传递给批处理脚本。

      2. 可以输入或粘贴注册表路径,带或不带双引号。

      3. 可以输入、粘贴或作为参数传递注册表路径,带或不带方括号。

      4. 注册表路径可以输入或粘贴或作为参数传递,也可以使用缩写的配置单元名称(HKCC、HKCU、HKCR、HKLM、HKU)。

      5. 批处理脚本检查是否已运行 Regedit,因为在 Regedit 已运行时启动 Regedit 时未显示注册表项。询问批处理用户是否应该杀死正在运行的实例以重新启动它以显示输入的注册表路径。如果批处理用户选择不杀死 Regedit,则在不设置输入路径的情况下启动 Regedit,导致(通常)只是将 Regedit 窗口置于前台。

      6. 批处理文件尝试自动获取位于英语 Windows XP My Computer、德语 Windows XP、Arbeitsplatz 和 Windows 上的注册表根名称7 只是计算机。如果 Regedit 的值 LastKey 在注册表中丢失或为空,这可能会失败。对于这种情况,请在批处理代码的第三行设置正确的根名称。

      【讨论】:

      • 尽管我的注册表根目录是“Computador”(pt-br),但我还是以“计算机”为根执行了命令,并且无论根名称如何,它都运行良好...
      • @kokbira 很高兴知道这个批处理文件也适用于巴西,并且它可以使用标签 GetRootName 下的代码自行找出 Computador 作为根名称,并在第 6 点进行了简要说明。
      【解决方案6】:

      复制以下文本并保存为批处理文件并运行

      @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
      

      在批处理文件提示时输入要打开的注册表项的路径,然后按Enter。 Regedit 打开该值中定义的键。

      【讨论】:

        【解决方案7】:

        我认为这个 C# 解决方案可能会有所帮助:

        通过利用之前的建议,我们可以欺骗 RegEdit 打开我们想要的密钥,即使我们不能将密钥作为参数传递。

        在本例中,“注册表设置”菜单选项将 RegEdit 打开到调用它的程序的节点。

        程序形式:

            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");
            }
        

        当然,您可以将所有内容放在表单的一种方法中,但我喜欢可重用性。

        【讨论】:

          【解决方案8】:

          这是一个基于上述https://stackoverflow.com/a/12516008/1179573 答案的简单 PowerShell 函数

          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
          

          上面的答案实际上并不能很好地解释它的作用。当您关闭 RegEdit 时,它会将您的最后一个已知位置保存在 HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit 中,因此这只是将最后一个已知位置替换为您要跳转的位置,然后将其打开。

          【讨论】:

            【解决方案9】:

            使用 clipboard.exe 和 regjump.exe 创建一个 BAT 文件 跳转到剪贴板中的键:

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

            (%~dp0 表示“BAT 文件的路径”)

            【讨论】:

            • 'clipboard' 不是内部或外部命令、可运行程序或批处理文件。
            【解决方案10】:

            lionkingrafiki's answer 的基础上,这是一个更强大的解决方案,它将接受一个 reg 密钥路径作为参数,并根据需要自动将 HKLM 转换为 HKEY_LOCAL_MACHINE 或类似的。如果没有参数,则脚本使用JScript hybrid chimera 调用的htmlfile COM 对象检查剪贴板。复制的数据将被拆分和标记化,因此它是否没有被修剪甚至在整个复制的污垢段落中都没有关系。最后,在修改LastKey 之前验证密钥的存在。包含空格的关键路径必须在双引号内。

            @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://stackoverflow.com/a/22697203/1683264
            >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://stackoverflow.com/a/15747067/1683264
            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);
                }
            });
            

            【讨论】:

              【解决方案11】:

              这似乎非常过时,但 Registration Info Editor (REGEDIT) Command-Line Switches 声称它支持这一点。

              【讨论】:

              【解决方案12】:

              您可以通过创建一个批处理文件(根据已经给出的提交)使其看起来像 regedit 执行此行为,但将其命名为 regedit.bat 并将其放在 C:\WINDOWS\system32 文件夹中。 (如果没有给出命令行参数,您可能希望它跳过编辑注册表中的最后一个键,因此“regedit”本身就像 regedit 一样工作)然后“regedit HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0”会做什么你想要的。

              这利用了 PATH 中的顺序通常是 C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;等等

              【讨论】:

                【解决方案13】:

                如果主要目标只是避免“点击”,那么在 Windows 10 中,您只需将目标路径键入或粘贴到 RegEdit 的地址栏中,然后按 Enter。

                这里的Computer\ 前缀是自动添加的。如果您只需键入或粘贴以例如开头的路径,它也将起作用。 HKEY_CURRENT_USER\....

                【讨论】:

                  【解决方案14】:

                  PowerShell 代码:

                  # 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
                  

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2018-10-28
                    • 1970-01-01
                    相关资源
                    最近更新 更多