Cleaning Up the Code
Finally, we clean up at the end of our script, and notify the value contained within the return status. Listing 6 shows you how to finalize the code and clean it up.
Listing 6 Finalizing Our Script and Returning the Return Status.
goto :end REM ********************************************************************************************* REM Script end REM ********************************************************************************************* :end REM Notify that the script has completed (echo Script " InstallSQLServerSP2.bat" completed with return value "%RETVAL%") (echo Script " InstallSQLServerSP2.bat" completed with return value "%RETVAL%") >> %LogFile%
And there we are. We have now completed our script for the installation of SP2. So what now? Simple, my valued readerwe modify the main.bat (our wrapper script) to initialize the variables we need and call our script if (and only if) our preceding script (InstallSQLServer.bat) succeeds.
Our main.bat script now contains a section that looks like Listing 7 (code in italics is from the third article in the series).
Listing 7Modifying main.bat to call the installation of SQL Server 2000 SP2.
if "%RETVAL%"=="0" goto :InstallSQLOK (echo ERROR: Installation of SQL Server failed "%RETVAL%".) (echo ERROR: Installation of SQL Server failed "%RETVAL%".) >> "%MainLogFile%" set RETVAL=%ERRORLEVEL% goto :end :InstallSQLOK REM Set up the parameters required for our SP upgrade script set NTAuthentication=Yes set SQLsaPwd= set TCPPort=1433 set AppPath=%driveletter%\sql2k.sp2\x86\setup set ISSDir=%TEMP% set LogFile=%TEMP%\SQLInstallSP2.log REM Now we are ready to execute our script Call InstallSQLServerSP2.bat if "%RETVAL%"=="0" goto :InstallSQLSP2OK (echo ERROR: Installation of SQL Server SP2 failed "%RETVAL%".) (echo ERROR: Installation of SQL Server SP2 failed "%RETVAL%".) >> "%MainLogFile%" set RETVAL=%ERRORLEVEL% goto :end :InstallSQLSP2OK :end REM Notify that the script has completed ...script continues from article 3...
NOTE
It is not 100% necessary to specify new values for all the variables you will use because some of them will persist from the InstallSQLServer.bat script. However, for completeness I have provided a value for all the variables that I will use in this subscript.
By now, you (like me) have seen the real power of installing a program such as SQL Server silently. With scripted installations, we can ensure that each installation is performed in the same manner, no matter what type of configuration (parameters) or what type of machine you are installing on (server or desktop). This can really ease the burden of system administration, and will give you real power and flexibility when it comes time to rebuild your SQL Server environments.