title: inno setup restart SQL Server windows service not working
body: <p>I am trying to install <code>SQL Server 2012</code> using <code>inno setup</code>. The installation part works fine. I am using a custom port to install the SQL server, so I change the port number in <code>Windows Registry</code> after the installation using <code>RegWriteStringValue</code> and trying to restart the SQL Server service in order to effect the changes.</p>
  
  <p>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.</p>
  
  <pre><code>procedure RestartService;
  var
  
      CommandLine: String;
      MyResultCode: Integer;
  begin       
          CommandLine := 'cmd /c NET STOP MSSQLSERVER /y &lt; "C:\test\yes.txt" &amp; NET START SQLSERVERAGENT &gt; C:\test\Output.txt';    
          Log('Command line is.. ' + CommandLine);
          Exec('cmd.exe', CommandLine, '', SW_HIDE, ewWaitUntilTerminated, MyResultCode);
          Sleep(20000);
  end;
  </code></pre>
  
  <p>The file <code>yes.txt</code> contains the character <strong>Y</strong> and a new line since restarting the service requires a prompt to restart the dependent service. </p>
  
  <p>When I open the Command prompt and run the command in the CommandLine directly, it works perfectly fine and gives me the following output.</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>But from the program, it does not seem to work and returns <code>MyResultCode</code> as 1 and also the file <code>Output.txt</code> which writes the output after running the command is empty. What am I missing?</p>
  
  <p>Thanks in advance,
  DeeJay.</p>