Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Command output as set variable  (Read 2534 times)

0 Members and 1 Guest are viewing this topic.

JADM

  • Guest
Command output as set variable
« on: February 03, 2007, 07:30:14 AM »
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.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Command output as set variable
« Reply #1 on: February 03, 2007, 01:43:22 PM »
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-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein