The below code explains How to install SQL server from the command prompt using configuration file. This example is Javascript based in TestComplete. You can take this example code as your starting point and change it as per your requirement.
Use the below functions-
function installCommand(path,arg) // passing path of installer and the arguments to this function. { var command = path + " " + arg; wshShell = Sys.OleObject("WScript.Shell"); result = wshShell.Run(command, 1,true); // wshShell.Run executes the command and returns the result code (0,1 etc). return result; }
function sqlinstallvalidate(batchfile) // pass the batchfile path to this function, the contents of batch file provided at end of this article { var servicename = "MSSQLSERVER" // If service name is different from default name then it can be passed in as parameter to this function var result = installCommand(batchfile,servicename) if(result == 0) //if successfull { result = installCommand("C:\\installers\\version.bat",'') // get the version of sql server var outputFile = "C:\\installers\\output.txt"; // the results from version.bat are stored in output.txt if (!aqFile.Exists(outputFile) && result == 0) aqFile.Create(outputFile); Log.Message(aqFile.ReadWholeTextFile(outputFile, aqFile.ctANSI)) // show the content of output.txt to confirm the version of SQL installed } if(result== 2) { Log.Message("Error observed during SQL server installation") } if(result== 1) { Log.Message("SQL service is stopped") } }
In the install function below, parameters are prepared and the call to installCommand function is made as shown below-
function install() { var sqlinstallerpath = "C:\\installers\\2008R2\\sql\\setup.exe" var arg = " /SAPWD=" + "" + " /ConfigurationFile=" + "C:\\config\\ConfigurationFile.ini" // the arguments can be set in configuration file as per your install requirement or can be passed in command line. installCommand(sqlinstallerpath,arg) // SQL server installer is initiated sqlinstallValidate(batchfile) //Validate the SQL server installation }
Contents of batchfile:
************************************
@echo off
rem pass the SQL service name to batch file
if “%1″==”” goto err
rem run the command to query the service status
sc query %1 | findstr RUNNING
rem conditions to check whether the service is started, stopped or errored.
if %ERRORLEVEL% == 2 goto error
if %ERRORLEVEL% == 1 goto stopped
if %ERRORLEVEL% == 0 goto started
echo unknown status
goto end
:error
exit /b 2
goto end
:started
exit /b 0
goto end
:stopped
exit /b 1
goto end
:err
exit /b -1
goto end
:end
**********************************