Windows script required to get InstalledInstances

  • 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.

  • 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

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Thanks a lot Eugene, it's working.

    Yes, i understand this is SQL forum. Can you suggest a good DOS forum pls.

  • 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.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply