Last active
December 14, 2025 01:57
-
-
Save tnhung2011/df6d04f686c0d819df5249dd093b42bf to your computer and use it in GitHub Desktop.
Read a value from the registry using a single path (HKXX or HKEY_ABC\SubKey\Value). Useful for lazy copy-pasting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal enableextensions enabledelayedexpansion | |
| for /f "usebackq eol= delims=" %%a in ('%*') do set sArgs=%%~a | |
| ::Split at last backslash ("\") | |
| for /f "delims==" %%a in ('set _a 2^>nul') do set "%%a=" | |
| (set lf=^ | |
| ) | |
| for %%l in ("!lf!") do set "_a=!sArgs:\=%%~l!" | |
| for /f %%i in ('set _a ^| find /v /c ""') do set /a skip=%%i-1 | |
| set flag= | |
| ::for/f skips empty lines | |
| for /f skip^=%skip%^ delims^=^ eol^= %%a in ("!_a!") do ( | |
| set "sArgs=!sArgs!!lf!" | |
| set flag=1 | |
| for %%l in ("!lf!") do set sArgs="!sArgs:\%%a%%~l=!" /v "%%a" | |
| ) | |
| if not defined flag set sArgs="!sArgs:~0,-1!" /ve | |
| ::Running reg.exe with no arguments return 0 in Windows XP, 1 in Windows Server 2003 and above | |
| ::They give different outputs for reg query | |
| reg >nul 2>nul && set skip=4 || set skip=2 | |
| for /f "tokens=2* skip=%skip%" %%a in ('reg query !sArgs!') do echo:%%b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment