在 NSIS 脚本中使用命令行参数实现依赖性检查

发布于 2024-12-19 21:15:53 字数 637 浏览 1 评论 0原文

我的目标是知道您是否使用任何检查或代码片段来确定在使用静默安装( /S param )将 NSIS 命令行参数传递到编译设置时是否存在某些依赖性。

NSIS 示例: http://nsis.sourceforge.net/Get_command_line_parameter_by_name

例如,如果我有三个参数:Setup.exe /S param1="" param2="" param3=""

如何检查以下secanrio:

${if} <Param1 is passed to Setup.exe> 
  <Param2 must ALSO be passed to Setup.exe>
${else}
  <Error message notifiing that Param1 is present, but dependent Param2 param is missing in CMD parameters>

谢谢!

我真的希望你至少能分享代码片段......如果不是完整的功能代码。

My goal is to know if you use any check or code snipp to determine if ther is some dependecy when passing NSIS command line params to copiled setup using Silent installation ( /S param ).

The NSIS sample: http://nsis.sourceforge.net/Get_command_line_parameter_by_name

For example, If I have three params: Setup.exe /S param1="" param2="" param3=""

How to check the following secanrio:

${if} <Param1 is passed to Setup.exe> 
  <Param2 must ALSO be passed to Setup.exe>
${else}
  <Error message notifiing that Param1 is present, but dependent Param2 param is missing in CMD parameters>

Thank you!

I really hope you will share at least code snipp ... if not whole functional code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2024-12-26 21:15:53
outfile test.exe
requestexecutionlevel user
silentinstall silent ;always force silent in this sample
!include LogicLib.nsh
!include FileFunc.nsh

Function StripOptPrefix
Exch $0
Push $1
StrCpy $1 $0 1
${If} $1 == "="
${OrIf} $1 == ":"
    StrCpy $0 $0 "" 1
${EndIf}
Pop $1
Exch $0
FunctionEnd
!macro StripOptPrefix var
Push ${var}
call StripOptPrefix
Pop ${var}
!macroend

Section
${GetParameters} $0
${If} $0 == ""
    ;No parameters, lets run the tests
    ExecWait '"$exepath" /param1=foo'
    ExecWait '"$exepath" /param1=foo /param2=bar'
${Else}
    ${GetOptions} $0 "/param1" $1
    ${If} ${Errors}
        # /param 1 not used, do nothing?
    ${Else}
        ${GetOptions} $0 "/param2" $2
        ${If} ${Errors}
            MessageBox mb_iconstop "Missing /param2, required by /param1"
            Quit
        ${Else}
            !insertmacro StripOptPrefix $1
            !insertmacro StripOptPrefix $2
            MessageBox mb_ok "1=$1$\n2=$2"
        ${EndIf}
    ${EndIf}
${EndIf}
SectionEnd
outfile test.exe
requestexecutionlevel user
silentinstall silent ;always force silent in this sample
!include LogicLib.nsh
!include FileFunc.nsh

Function StripOptPrefix
Exch $0
Push $1
StrCpy $1 $0 1
${If} $1 == "="
${OrIf} $1 == ":"
    StrCpy $0 $0 "" 1
${EndIf}
Pop $1
Exch $0
FunctionEnd
!macro StripOptPrefix var
Push ${var}
call StripOptPrefix
Pop ${var}
!macroend

Section
${GetParameters} $0
${If} $0 == ""
    ;No parameters, lets run the tests
    ExecWait '"$exepath" /param1=foo'
    ExecWait '"$exepath" /param1=foo /param2=bar'
${Else}
    ${GetOptions} $0 "/param1" $1
    ${If} ${Errors}
        # /param 1 not used, do nothing?
    ${Else}
        ${GetOptions} $0 "/param2" $2
        ${If} ${Errors}
            MessageBox mb_iconstop "Missing /param2, required by /param1"
            Quit
        ${Else}
            !insertmacro StripOptPrefix $1
            !insertmacro StripOptPrefix $2
            MessageBox mb_ok "1=$1$\n2=$2"
        ${EndIf}
    ${EndIf}
${EndIf}
SectionEnd
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文