how to get the string after "REG_SZ" or "REG_DWORD"?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

how to get the string after "REG_SZ" or "REG_DWORD"?

#1 Post by nnnmmm » 03 Feb 2025 20:36

SET "RR1=HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
SET "RR2=%~dp0dunedynasty.exe"

reg query "%RR1%" /v "%RR2%"
returns

Code: Select all

W:\\Dune 2 - Remake\\dunedynasty.exe REG_SZ WINXPSP3
1             2 3 4                                      5          6
FOR /F "TOKENS=6" %%V in ('reg query "%RR1%" /v "%RR2%"') DO (SET DUNE2dyn=%%V)
ECHO "%DUNE2dyn%"(WINXPSP3 is the string answer i need)

the problem with the TOKENS method i currently know is that getting the string which i need depends on the directory name, that is how many spaces are in there
***************************************************************************
another example - TOKENS=3 in this case
1>nul 2>nul reg query "HKCU\Control Panel\Desktop" /v "ScreenSaveActive"
FOR /F "TOKENS=3" %%%%V in ('reg query "HKCU\Control Panel\Desktop" /v "ScreenSaveActive"') DO (SET ScnSaverData=%%%%V)

is there a command or a way to get the string after "REG_SZ" or "REG_DWORD"?
aaa bbb ccc d e f 123 REG_DWORD x01
the answer is x01

miskox
Posts: 646
Joined: 28 Jun 2010 03:46

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#2 Post by miskox » 05 Feb 2025 01:34

Here are two methods: string replacement or FOR.

Code: Select all

@echo off
echo method 1
echo # should not be in the folder name or file name. Should be changed otherwise.

set value1=W:\\Dune 2 - Remake\\dunedynasty.exe REG_SZ WINXPSP3

echo value1=%value1%

set value2=%value1: REG_SZ =#%
set value2=%value1: REG_DWORD =#%
echo value2=%value2%

for /f "tokens=2 delims=#" %%f in ("%value2%") do set value3=%%f

echo value3=%value3%

echo method 2


set value1=W:\\Dune 2 - Remake\\dunedynasty.exe REG_SZ WINXPSP3
for %%d in (%value1%) do set value3=%%d

echo value3=%value3%
Output:

Code: Select all

c:\>
method 1
# should not be in the folder name or file name. Should be changed otherwise.
value1=W:\\Dune 2 - Remake\\dunedynasty.exe REG_SZ WINXPSP3
value2=W:\\Dune 2 - Remake\\dunedynasty.exe#WINXPSP3
value3=WINXPSP3
method 2
value3=WINXPSP3

c:\>

Saso

Update: added REG_DWORD replacement line.

nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#3 Post by nnnmmm » 14 Feb 2025 03:36

set "CompLayer=WINXPSP3"
SET "RR1=HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
SET "RR2=%~dp0dunedynasty.exe"

RR2 is a random game EXE file, it can have many different strings like WINXPSP3 or Win98 or Win8 ~WinXPSP2 ....

1st process
FOR /F "Delims=" %%V in ('reg query "%RR1%" /v "%RR2%"') DO (SET DUNE2dyn=%%V)
%DUNE2dyn% could return W:\Dune 2 - Remake\dunedynasty.exe REG_SZ WINXPSP3 or Win98 or Win7 or ~winxp......

2nd process(i keep forgetting the simplest FOR DO, it takes the last read as the variable)
FOR %%V IN (%DUNE2dyn%) DO SET AA=%%V
ECHO %AA%

IF %AA%==%CompLayer% GOTO :dothis
IF NOT %AA%==%CompLayer% GOTO :dothat

thanks for method 2, letting me see it gave me the instant answer
Last edited by nnnmmm on 20 Feb 2025 02:15, edited 1 time in total.

nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#4 Post by nnnmmm » 19 Feb 2025 09:23

reg query "%WallReg%" /v "Wallspaper"
" (1) Wallpaper (2) REG_SZ (3) m:\GRAN (4) D (5) D001.BMP"

i thought i got this by reading the last string but when the last was broken, it went back to the drawing board

how would i universally get the string "m:\GRAN D D001.BMP" with spaces
when the reg could look all broken like below

wa ll paper REG_SZ m:\GRAN D D001.BMP
Last edited by nnnmmm on 20 Feb 2025 02:12, edited 1 time in total.

nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#5 Post by nnnmmm » 20 Feb 2025 02:12

i got it working after searching 4 hours all day on the internet, none worked or too long and not worked at the same time except for one from this forum, which i didnt understand swapping but i am getting there

REM -------luckily left trim was not needed but.... string swapping REG_SZ with ~
FOR /F "tokens=1,2 delims=~" %%A in ("%WallP1:REG_SZ=~%") DO (SET Word1=%%A &SET Word2=%%B)

miskox
Posts: 646
Joined: 28 Jun 2010 03:46

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#6 Post by miskox » 20 Feb 2025 12:52

I don't know if parenthesis ( "(" and ")" ) are part of the string. So if they are not then maybe you could just remove strings 'wallpaper' and 'reg_szs' and you have a result. Or maybe take a colon (:) as a delimiter. Take the first argument and take the last character and then add the second argument.

If parenthesis are part of the string then you can use them as delimiters - if there is a fixed number of them.

You don't provide enough info to give a better answer.

Saso

nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

Re: how to get the string after "REG_SZ" or "REG_DWORD"?

#7 Post by nnnmmm » 22 Feb 2025 22:45

>I don't know if parenthesis ( "(" and ")" ) are part of the string.
FOR /F "tokens=1,2 delims=~" %%A in (%WallP1:REG_SZ=~%) DO (SET Word1=%%A &SET Word2=%%B)
i tried and it caused an error that said, system can not find wallpaper

reg query "HKCU\some program\name" /v "wallpaper in this case" could produce a result
(some strings with spaces ) REG_SZ (some strings with spaces )
W:\some future fullname with spaces REG_SZ m:\GRAN D D001.BMP

i understood swapping "REG_SZ" with "~" so that tokens could work on ~ and read the rest of the string as a whole

Post Reply