Batch script to install SQLServer

  • I have a file INST.txt in a folder which has got SQL instance names in it in just 3 lines. Ex :

    INSTANCE1

    INSTANCE2

    INSTANCE3

    I want to compare each of the above value to a string value in registry at : REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"

    If not found, I have to install that instance. Otherwise skip to next value.

    I tried like below, but doesn't work. If not found in registry, i get an ERROR saying : THe system cannot find the specified value in registry. Can someone modify please. I need urgently.

    for /f "tokens=1 delims=" %%b in ('type C:\MSSQL10\INST.txt') do (REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" /v "%%b")

    IF %ERRORLEVEL% EQU 0 (

    Echo "Instance found. Do nothing"

    ) else (

    Echo "executing : " %%b

    "C:\Inst\setup.exe"

    )

    )

  • Not really a SQL question 😛

    It has been a while since I did anything like this, but I think you need to suppress the error report.

    for /f "tokens=1 delims=" %%b in ('type C:\MSSQL10\INST.txt') do (REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" /v "%%b" 1>nul 2>&1)

    if errorlevel 1 (

    Echo "executing : " %%b

    "C:\Inst\setup.exe"

    ) else (

    Echo "Instance found. Do nothing"

    )


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • :hehe:

    Yes you should go to vb.net forum to match your questions ,but he reply you right

    :w00t:

  • johnitech.itech (2/1/2012)


    :hehe:

    Yes you should go to vb.net forum to match your questions ,but he reply you right

    :w00t:

    What has vb.net got to do with this question?


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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