Problems with FOR command syntax

Microsoft Windows xp pro with sp3 multil...
February 1, 2010 at 07:26:49
Specs: Windows XP
I am not sure what I am doing wrong here. I am trying to read the 3rd token from output of a find comand. All I can get it to return is echo %%A

Here is what I have
FOR /F "tokens=3* delims= " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" ^| find "productname"') do echo %%A

The output of the reg query command looks like this ProductName REG_SZ Microsoft Windows XP I am trying to filter out the first two tokens so that I can capture it as a variable.

Any ideas?


See More: Problems with FOR command syntax

Report •

February 1, 2010 at 07:57:25
find "productname"
It's "ProductName", not "productname"; it's case sensitive. If successful, it'll display "Microsoft", which probably isn't what you want. echo %%B will give you (according to your OS field) "Windows XP". If you want the entire "Microsoft Windows XP", adjust your tokens= to tokens=2*.

EDIT: Forgot to mention it before, but get rid of the delims= part.

Report •

February 1, 2010 at 09:45:05
It's also possible to remove the find process by using the
for /f loop and reg more effectively:

for /f "skip=4 tokens=2*" %%a in ('2^>nul reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ProductName"') do (
    echo %%b

Batch Variable how to

Report •
Related Solutions

Ask Question