我怎样才能使这个功能在 NSIS 中实际工作? [英] How can I make this function actually work in NSIS?
问题描述
我正在尝试找出我的 NSIS 安装程序中的一段代码.片段如下:
I am trying to factor out a snippit of code I have ALL OVER my NSIS installer. The snippet is as follows:
nsExec::ExecToStack 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Pop $0
${If} $0 != 0
Pop $0
Push ".NET 3.5 failed to install: $\n$0"
Call DetailPrintTS
StrCpy $Errors "$Errors Errors From .NET 3.5 install:$\n$0$\n$\n"
${EndIf}
所以我想将其分解为:
Function LoggedExec
Pop $0
Pop $1
nsExec::ExecToStack $0
Pop $0
${If} $0 != 0
Pop $0
Push "$1 failed to install: $\n$0"
Call DetailPrintTS
StrCpy $Errors "$Errors Errors From $1 install:$\n$0$\n$\n"
${EndIf}
FunctionEnd
然后按如下方式调用它:
and then call it as follows:
Push 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Push '.NET 3.5'
Call LoggedExec
请注意,DetailPrintTS 是我在 DetailPrint 中包含时间戳的另一个函数:
Note that DetailPrintTS is another function I made that includes a timestamp in DetailPrint:
Function DetailPrintTS
Pop $7
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
DetailPrint "$4:$5:$6 -- $7$\n"
FunctionEnd
推荐答案
记住 Push
/Pop
是作用在一个堆栈上(换句话说,一个 lifo:last进,先出).
Remember that Push
/ Pop
are acting on a stack (in other words, a lifo: last in, first out).
从您的代码片段中,您似乎以与 Push
相同的顺序 Pop
中的参数 LoggedExec
.相反,如果你Push
命令并在日志文本之后,你需要以相反的顺序Pop
:
From your snippet, you seem to Pop
the arguments in LoggedExec
in the same order that they were Push
ed. Instead, if you Push
the command and after the text for the log, you need to Pop
in reversed order:
Push 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Push '.NET 3.5'
Call LoggedExec
;in LoggedExec
pop $1
pop $0
这篇关于我怎样才能使这个功能在 NSIS 中实际工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!