title: Execute SQLcmd and then return query result as variable to NSIS
body: <p>I am creating an NSIS installer and I need to get the version of SQL server the users has installed. </p>
  
  <p>The user will give me the instance name so I can connect to the box. Then I run this sql query select SERVERPROPERTY ('ProductMajorVersion') and get the major version number.</p>
  
  <p>But when I try to do is from NSIS I am not succeeding as it errors when it is executing the query so I do not get the result from the console window.</p>
  
  <p>Below is what I have in my NSIS file:</p>
  
  <pre><code>nsExec::ExecToStack "'sqlcmd -S $SQL_Instance_Name -E -h-1 -Q $\"SET NOCOUNT ON; select SERVERPROPERTY ($\'ProductMajorVersion$\')$\"'"
  
      Pop $0
      Pop $1
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>ExecCmd::Exec  "'sqlcmd -S $SQL_Instance_Name -E -h-1 -Q $\"SET NOCOUNT ON; 
  select SERVERPROPERTY ($\'ProductMajorVersion$\')$\"'"
  
      Pop $0
      Pop $1
  </code></pre>
  
  <p>But I am just not getting my desired result any advise or suggestions would be appreciated.</p>
  
  <p>Alternatively if there in easier and quicker way to get this information from the Registry then that would be fine as well.</p>
  
  <p>TIA
  Andy</p>