1.

Solve : Command output as set variable?

Answer»

hi boys and girls of course,

im trying to wirte a bat. file that returnes a value out of the registry.

Code: [Select]set KEY=reg QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\THQ\Dawn of War" /v CDKEY
echo %KEY%

well, my issue is RATHER simple. the set command dosnt see the reg query as a command, but as a string.
Does ANYBODY maybe have an IDEA how to make the output of "reg query "HKEY_LOCAL_MACHINE\SOFTWARE\THQ\Dawn of War" /v CDKEY"
a variable. The problem ist the command gives me this output

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\THQ\Dawn of War
CDKEY REG_SZ ****-****-****-****

, but i only need the key itself. thx 4 the patience.This should work for this specific case but do not use as a template for all cases:

Code: [Select]for /f "tokens=1-3 delims=" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\THQ\Dawn of War" /v "cdkey" ^| find /i "cdkey"') do (
set key=%%k
)
echo %key%

Hope this helps. 8-)



Discussion

No Comment Found