NSIS - print for query during command line installation

I create installers for Windows using NSIS and have several custom installation options that the user can specify using the command line, for example:

installer.exe /IDPATH=c:\Program Files\Adobe\Adobe InDesign CS5 /S 

What I want to do is to show these parameters for the person who is installing. I can easily make out /? or / help with the options $ {GetParameters} and $ {GetOptions}, but how do I actually print on the command line?

+6
command-line-arguments nsis
source share
1 answer

NSIS is a GUI program and does not actually have the ability to write to standard output.

In XP and later, you can do this with a system plugin:

 System::Call 'kernel32::GetStdHandle(i -11)i.r0' System::Call 'kernel32::AttachConsole(i -1)' FileWrite $0 "hello" 

On <XP, there is no AttachConsole, and you need to call AllocConsole on these systems (probably a new console window will open)

Edit: You can open a new console if the parent process no longer has

 !include LogicLib.nsh System::Call 'kernel32::GetStdHandle(i -11)i.r0' System::Call 'kernel32::AttachConsole(i -1)i.r1' ${If} $0 = 0 ${OrIf} $1 = 0 System::Call 'kernel32::AllocConsole()' System::Call 'kernel32::GetStdHandle(i -11)i.r0' ${EndIf} FileWrite $0 "hello$\n" 

But it really makes no sense until /? processing is in progress, you can also open a message box when there is no console

 !include LogicLib.nsh StrCpy $9 "USAGE: Hello world!!" ;the message System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;try to get stdout System::Call 'kernel32::AttachConsole(i -1)i.r1' ;attach to parent console ${If} $0 <> 0 ${AndIf} $1 <> 0 FileWrite $0 "$9$\n" ${Else} MessageBox mb_iconinformation $9 ${EndIf} 
+9
source share

All Articles