Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
jestes1013
- Posts: 1
- Joined: 30 Oct 2009 07:41
#1
Post
by jestes1013 » 30 Oct 2009 08:17
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.
-
avery_larry
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
#2
Post
by avery_larry » 02 Nov 2009 10:59
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