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

问题描述 投票:6回答:2

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

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

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

nsis command-line-arguments
2个回答
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}

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}

首先连接控制台然后获取std句柄。在附加句柄之前(通常会)无效。

© www.soinside.com 2019 - 2024. All rights reserved.