1

I am creating an NSIS installer and I need to get the version of SQL server the users has installed.

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.

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.

Below is what I have in my NSIS file:

nsExec::ExecToStack "'sqlcmd -S $SQL_Instance_Name -E -h-1 -Q $\"SET NOCOUNT ON; select SERVERPROPERTY ($\'ProductMajorVersion$\')$\"'"

    Pop $0
    Pop $1

I have also tried:

ExecCmd::Exec  "'sqlcmd -S $SQL_Instance_Name -E -h-1 -Q $\"SET NOCOUNT ON; 
select SERVERPROPERTY ($\'ProductMajorVersion$\')$\"'"

    Pop $0
    Pop $1

But I am just not getting my desired result any advise or suggestions would be appreciated.

Alternatively if there in easier and quicker way to get this information from the Registry then that would be fine as well.

TIA Andy

1
  • 1
    +1 Got here from first google result. The question outlines the issue and what was tried (And formatting is done properly for code!) Shame on the user that downvoted without any stated (constructive) criticism. Commented Nov 20, 2019 at 19:55

1 Answer 1

1

The application should be specified with a full path and it needs to be quoted with a double quotes:

To ensure that command are executed without problems on all windows versions, is recommended to use the following syntax:

nsExec::ExecToStack [OPTIONS] '"PATH" param1 param2 paramN'

Section
StrCpy $0 "-S $SQL_Instance_Name ....." ; Putting the parameters here makes them easier to debug etc
MessageBox mb_ok $0 ; Use this to make sure the parameters look correct
nsExec::ExecToStack '"c:\path\to\sqlcmd.exe" $0'
Pop $0
Pop $1
DetailPrint $0,$1 ; $0 will be "error" if nsExec cannot start the application
SectionEnd
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Anders, Thank you very much for the reply I see what I was doing wrong and it now works so thanks again. Just out of personal learning, why do I have a -1 against my question, what did I do wrong do you know? Andy
That is just how SO works, somebody did not like your question for whatever reason and voted it down. You did not do anything wrong but I also found your question a bit lacking and my answer was just a guess because of it. Ideally you should also have posted the content of $0 and $1, if you had done that and it said "error" then things would be easier to diagnose...
Hi Anders, I appreciate the feed back will endeavour to make future questions clearer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.