June 14, 2012 at 4:28 am
Hi,
I just want to loop through and ECHO the InstalledInstances values in registry using Windows command script.
I tried this, but it did not give the required output.
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" /v InstalledInstances') DO ECHO %%B
ECHO %SQLInstance%
It gave output on single line : INST1\0INST2\0INST3
I don't know what is this \0
I want it to be displayed like :
INST1
INST2
INST3
Can some one please post the code or direct me to any site.
June 14, 2012 at 6:43 am
It kind of SQL forum, not the DOS one...
It took me a while to figure out how to do it in DOS using REG QUERY, you need to follow all tips mentioned...
ECHO OFF
REM Please note: in Windows 7 you need to skip only 2 lines instead of 4...
FOR /F "skip=4 tokens=2*" %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" /v InstalledInstances') DO SET vals=%%B
SETLOCAL EnableDelayedExpansion
REM !!!IMPORTANT!!!: Two empty lines after the next SET statement is a crucial
REM requirement for this code to work, it helps to create
REM LF separated string which you can use in FOR /F!
SET LF=^
FOR /F "delims=" %%i in ("%vals:\0=!LF!%") do echo %%i
June 14, 2012 at 7:28 am
Thanks a lot Eugene, it's working.
Yes, i understand this is SQL forum. Can you suggest a good DOS forum pls.
June 14, 2012 at 7:49 am
Sorry mate, I don't know the one. And I guess there are no many as not many DOS programmers are still around...
Windows engineers forums will be your best bet.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply