NSIS - 在命令行安装期间打印以提示

时间:2010-06-23 15:48:43

标签: nsis command-line-arguments

我正在使用NSIS为Windows创建安装程序,并且有许多用户可以使用命令行指定的自定义安装选项,例如:

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

我想要做的是向安装人员显示这些选项。我可以轻松解析/?或者使用$ {GetParameters}和$ {GetOptions}帮助参数,但如何在命令提示符下进行实际打印?

2 个答案:

答案 0 :(得分:9)

NSIS是一个GUI程序,并没有真正能够写入stdout。

在XP及更高版本中,您可以使用系统插件执行此操作:

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

开< XP,没有AttachConsole,你需要在这些系统上调用AllocConsole(可能会打开一个新的控制台窗口)

修改 如果父进程没有

,则可以打开一个新控制台
!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" 

但就它而言,它真的没有任何意义吗?处理时,你可以在没有控制台时打开一个消息框

!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}

答案 1 :(得分:0)

!include LogicLib.nsh
StrCpy $9 "USAGE: Hello world!!" ;the message
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
${If} $0 != 0
 System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
 FileWrite $0 "$9$\n" 
${Else}
 ;no console to attach -- show gui message
 MessageBox mb_iconinformation $9
${EndIf}

First attach console then get std handle. Before attach handles may (often will) be invalid.