Page 1 of 1

For /f Need help

Posted: 30 Oct 2009 08:17
by jestes1013
I have

Code: Select all

@ECHO OFF
for /f "skip=2 delims=" %%a in ('
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server"
') do (
    for /f "skip=4 tokens=2,* delims=   " %%b in ('
        2^>nul reg query "%%a" /v "InstalledInstances"
    ') do (
        if not errorlevel 1 (
            Echo %%c
        )
    )
)
Pause


Which produces:
ALLDATASC\0SQLEXPRESS\0\0

I am trying to get:
ALLDATASC
SQLEXPRESS
...and so on.

Posted: 02 Nov 2009 10:59
by avery_larry
Can't test very well since those keys don't exist on my machine, but you want to use a \ as a delimiter in the 2nd for loop, possibly instead of a space, or in addition to. You may also want more tokens:




Code: Select all

@ECHO OFF 
for /f "skip=2 delims=" %%a in ('
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server"
') do (
    for /f "skip=4 tokens=2-5 delims=\" %%b in ('
        2^>nul reg query "%%a" /v "InstalledInstances"
    ') do (
        if not errorlevel 1 (
            Echo %%c
            Echo %%d
            Echo %%e
        )
    )
)
Pause