NSIS nsi脚本错误: - !insertmacro:找不到名为“SECTION_BEGIN”的宏

问题描述 投票:0回答:1

在带有MUI2.nsh的nsi脚本中

码:-

!macro SECTION_BEGIN

Section ""

Call zip2exe.SetOutPath

!macroend

!macro SECTION_END

SectionEnd

!macroend

但是,如果我想定义两个或更多部分,那么在这种情况下如何合并SECTION_BEGIN部分?

Section "Main Component" MainCom
  #SectionIn RO # Just means if in component mode this is locked

    Call zip2exe.SetOutPath

  ;Store installation folder in registry
  WriteRegStr HKLM "Software\${ZIP2EXE_NAME}" "" $INSTDIR

  ;Registry information for add/remove programs
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ZIP2EXE_NAME}" "DisplayName" "${ZIP2EXE_NAME}"

  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ZIP2EXE_NAME}" "NoRepair" 1

  ;Create optional start menu shortcut for uninstaller and Main component


  ;Create uninstaller
  WriteUninstaller "${ZIP2EXE_NAME}_uninstaller.exe"
#!macroend

#!macro SECTION_END

SectionEnd

#!macroend


;--------------------------------
;Uninstaller Section

Section "Uninstall"

  ;Delete the appdata directory + files
  RMDir /r "${INSTDIR_DATA}\*.*"
  RMDir "${INSTDIR_DATA}"

  ;Delete Start Menu Shortcuts
  Delete "$SMPROGRAMS\${ZIP2EXE_NAME}\*.*"
  RmDir  "$SMPROGRAMS\${ZIP2EXE_NAME}"

SectionEnd
#!macro SECTION_END

如果我们省略SECTION_BEGIN部分,则会出现错误。如果我们在两个部分都提到SECTION_BEGIN,那么也会出现错误。这个问题的解决方案是什么?

nsis
1个回答
1
投票

如果实际上想要使用Zip2Exe,那么你可以修改NSIS\Contrib\zip2exe\Base.nsh的部分

!macro SECTION_END

  SectionEnd

!macroend

这样的事情

!macro SECTION_END

  SectionEnd

  !if /FileExists "c:\mycustomzip2exefiles\mycustomsections.nsh"
  !include "c:\mycustomzip2exefiles\mycustomsections.nsh"
  !endif

!macroend

然后你可以在c:\mycustomzip2exefiles\mycustomsections.nsh中输入你想要的任何代码:

Section "My other section"
SetOutPath $InstDir
File "anotherfile.txt"
SectionEnd

但是,Zip2Exe主要用于创建简单的自解压可执行文件,您不应该使用它来创建完整的安装程序。

当你创建一个真正的安装程序,你不使用Zip2Exe,你使用MakeNSIS并没有SECTION_BEGIN宏这样的东西,你只需要添加任意数量的.NSI文件。

Example2.nsi包含一个基本的安装程序/卸载程序。

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