0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

指定したキーでレジストリエディタを開くバッチファイル!!!

Last updated at Posted at 2023-03-26

「 これでどうだ!」 の完成型 . . . と おもいたい。

OpenRegKey.cmd
@REM Open RegEdit to a Specific Key.
@REM It might be better to run it as administrator.
::https://www.ka-net.org/blog/?p=11415
::https://kimama9.blog.fc2.com/blog-entry-981.html
@if not "%~0"=="%~dp0.\%~nx0" start /max %ComSpec% /c ^""%~dp0.\%~nx0" %*^" & exit
@echo off
setlocal
set HKCR=HKEY_CLASSES_ROOT
set HKCU=HKEY_CURRENT_USER
set HKLM=HKEY_LOCAL_MACHINE
set HKU=HKEY_USERS
set HKCC=HKEY_CURRENT_CONFIG
set localize=1
set chk_args=%1
if defined chk_args set keys=%* & goto :set_keys
for /f "tokens=2,* delims= " %%A in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey"') do set "LastKey=%%B"
:last_key
cls
echo.
if defined LastKey (
    echo "Last referenced key = %LastKey%"
    echo.
    set q=
    set /p q="Open just it [Y,N]? "
) else (
    set q=n
)
if /i "%q%"=="y" (
    set "k=%LastKey%"
    goto :set_last
) else if /i "%q%"=="n" (
    goto :set_keys
) else (
    goto :last_key
)
:set_keys
cls
echo.
set k=
set /p k="Which key to open?: "
:set_last
if defined k set "k=%k:^=^^%"
if defined k (
    set /a localize=localize+2
    if %localize% lss 31 (
        set "k=%k:!=^!%"
        setlocal enabledelayedexpansion
        for /f "tokens=1,2,* delims=\" %%A in ("!k!") do (
            for %%X in (HKCR HKCU HKLM HKU HKCC) do (
                if /i "%%A"=="%%X" set "k=!%%X!\%%B\%%C" & goto :break
                if /i "%%B"=="%%X" set "k=%%A\!%%X!\%%C" & goto :break
            )
            set "k=%%A\%%B\%%C"
        )
        :break
        setlocal disabledelayedexpansion
        call :rmbks
    )
    if %localize% geq 31 (
        echo Full stomach, surrender.
        pause >nul
        echo I can't eat anymore, take a break.
        pause
        start /i %ComSpec% /c ^""%~f0" %keys%^"
        exit
    )
)
set ^"keys=%keys%"%k%" ^"
echo.
echo [ %keys%]
:loop
echo.
set q=
set /p q="More [Y,N]?: "
if /i "%q%"=="y" (
    goto :set_keys
) else if /i "%q%"=="n" (
    call :opn_reg %keys%
) else (
    goto :loop
)
exit
:opn_reg
echo.
:loop2
set "target=%1"
if not defined target exit /b
call :hold
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /t REG_SZ /d %target% /f
start regedit /m
shift /1
goto :loop2
:hold
set ep=%time:~-2,1%
if %ep% lss 5 (set /a ep=ep+5) else (set /a ep=ep-5)
:adjust
if %ep% equ %time:~-2,1% exit /b
goto :adjust
:rmbks
if not defined k (
    exit /b
) else if not "%k:~-1%"=="\" (
    exit /b
) else (
    set "k=%K:~0,-1%"
    goto :rmbks
)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?