Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

REG QUERY ???

Apr
1,794
15
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

  • path2pic.bat
    222 bytes · Views: 289
compare the output of the BTM in this message with the BAT from the one above....
 

Attachments

  • path2pic.btm
    322 bytes · Views: 306
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
 
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 ?
 
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
 
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
 
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.
 
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:
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
 
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 :
 
Back
Top