I am trying to install SQL Server 2012
using inno setup
. The installation part works fine. I am using a custom port to install the SQL server, so I change the port number in Windows Registry
after the installation using RegWriteStringValue
and trying to restart the SQL Server service in order to effect the changes.
But for some reason my logic to restart the service is not working through my code. I use the below procedure to achieve the same.
procedure RestartService;
var
CommandLine: String;
MyResultCode: Integer;
begin
CommandLine := 'cmd /c NET STOP MSSQLSERVER /y < "C:\test\yes.txt" & NET START SQLSERVERAGENT > C:\test\Output.txt';
Log('Command line is.. ' + CommandLine);
Exec('cmd.exe', CommandLine, '', SW_HIDE, ewWaitUntilTerminated, MyResultCode);
Sleep(20000);
end;
The file yes.txt
contains the character Y and a new line since restarting the service requires a prompt to restart the dependent service.
When I open the Command prompt and run the command in the CommandLine directly, it works perfectly fine and gives me the following output.
The following services are dependent on the SQL Server (MSSQLSERVER) service.
Stopping the SQL Server (MSSQLSERVER) service will also stop these services.
SQL Server Agent (MSSQLSERVER)
The SQL Server Agent (MSSQLSERVER) service is stopping.
The SQL Server Agent (MSSQLSERVER) service was stopped successfully.
The SQL Server (MSSQLSERVER) service is stopping.
The SQL Server (MSSQLSERVER) service was stopped successfully.
But from the program, it does not seem to work and returns MyResultCode
as 1 and also the file Output.txt
which writes the output after running the command is empty. What am I missing?
Thanks in advance, DeeJay.