REG QUERY ???

Apr 2, 2011
1,281
3
53
North Carolina, USA
Given the following:

REG QUERY "HKCU\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperSource

How would I echo the value of WallpaperSource and not what the command fully echos ?

Win 7/ 64 TCMD V24.02.49
 

Attachments

May 20, 2008
10,623
81
Syracuse, NY, USA
How would I echo the value of WallpaperSource and not what the command fully echos ?
Obviously you know how to do it with @REGQUERY. Is there still a question? My WallpaperSource is empty so with another example, here's one way to do it.

Code:
v:\> REG QUERY "HKCU\Console" /v FaceName

HKEY_CURRENT_USER\Console
    FaceName    REG_SZ    Andale Mono


v:\> REG QUERY "HKCU\Console" /v FaceName | ffind /k /m /t"FaceName" | (do l in @con ( echo %@word[2-,%l]))
Andale Mono
 
Apr 2, 2011
1,281
3
53
North Carolina, USA
I guess my question boils down to how can I get REG QUERY to just say the value of WallpaperSource and not the extra stuff that the command outputs - using stuff that is in CMD and will also work in TCMD ?
 
May 20, 2008
10,623
81
Syracuse, NY, USA
This works in TCC and CMD but it only represents a strategy (which, in other situations, could require a lot of monkeying around).
Code:
v:\> for /f "tokens=1-4" %a in ('REG QUERY HKCU\Console /v FaceName') do @if not "%c" == "" echo %c %d
Andale Mono
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Here's another which, in general, might require less massaging.

Code:
v:\> type gg.bat
@echo off
set answer=
for /f "tokens=*" %%a in ('REG QUERY HKCU\Console /v FaceName ^| findstr FaceName') do @set answer=%%a
echo %answer:~22,100%
Code:
v:\> ver

TCC  24.02.49   Windows 7 [Version 6.1.7601]

v:\> gg.bat
Andale Mono

v:\> cmd /c gg.bat
Andale Mono
 
May 20, 2008
10,623
81
Syracuse, NY, USA
22 is the offset on the line where a REG_SZ starts (found by experimenting). The 100 means the next 100 characters (I figured that'd be enough). And the last % is just the end of the variable reference. If you're not up on CMD's environment variable manipulations, do "SET /?" in CMD.
 
Aug 3, 2016
376
9
Netherlands
Try it with:
Code:
for /f "skip=1 tokens=2,* usebackq" %x in (`reg query "HKCU\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperSource`) do set RESULT=%y
 
Last edited:
May 20, 2008
10,623
81
Syracuse, NY, USA
Nice one Maarten. skip=2 seems OK with both TCC and CMD.

Code:
v:\> ver

TCC  24.02.49   Windows 7 [Version 6.1.7601]

v:\> for /f "skip=2 tokens=2,* usebackq" %a in (`REG QUERY HKCU\Console /v FaceName`) do @echo %b
Andale Mono

v:\> cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
v:\> for /f "skip=2 tokens=2,* usebackq" %a in (`REG QUERY HKCU\Console /v FaceName`) do @echo %b
Andale Mono
In a batfile too.

Code:
v:\> type xx.bat
@echo off
ver
for /f "skip=2 tokens=2,* usebackq" %%a in (`REG QUERY HKCU\Console /v FaceName`) do @echo %%b
v:\> xx.bat

TCC  24.02.49   Windows 7 [Version 6.1.7601]
Andale Mono

v:\> cmd /c xx.bat

Microsoft Windows [Version 6.1.7601]
Andale Mono
 
May 20, 2008
10,623
81
Syracuse, NY, USA
It seems a bit odd but in my example, skip=1 and skip=2 both work in CMD (while only skip=2 works in TCC).

Code:
v:\> ver

Microsoft Windows [Version 6.1.7601]

v:\> for /f "skip=1 tokens=2,* usebackq" %a in (`REG QUERY HKCU\Console /v FaceName`) do @echo %b
Andale Mono

v:\> for /f "skip=2 tokens=2,* usebackq" %a in (`REG QUERY HKCU\Console /v FaceName`) do @echo %b
Andale Mono
In fact, skip=2 (which works in both shells) seems correct since the output starts with an empty line.

Code:
v:\> REG QUERY HKCU\Console /v FaceName | type /l
   1 :
   2 : HKEY_CURRENT_USER\Console
   3 :     FaceName    REG_SZ    Andale Mono
   4 :