【问题标题】:How to copy files from installer without install如何在不安装的情况下从安装程序复制文件
【发布时间】:2019-09-25 07:27:19
【问题描述】:

我已经使用 NSIS 创建了安装程序。

如果自动安装失败,我有一个需要运行的批处理文件(安装程序会检查是否已经存在任何版本的软件,如果存在则第一次卸载它。)。

如何在不安装的情况下从安装程序运行批处理文件?

【问题讨论】:

  • 抱歉,您的问题离题了,您没有提供一个最小、完整和可验证的示例。
  • 不管你的问题是关于特定软件的使用,而不是关于编程。因此,您的建议是阅读该软件的使用信息,然后在发布问题之前尝试实施您所学的内容。
  • “如果自动安装失败需要运行”这里的意思是自动卸载吗?

标签: batch-file windows-installer nsis


【解决方案1】:

NSIS 并不真正关心您是否将文件提取到 $InstDir 或其他地方:

!define UninstId "MyAppBlahBlah"
!include LogicLib.nsh

Function RunMyBatch
  InitPluginsDir
  SetOutPath $PluginsDir
  File "myfiles\mybatch.bat"
  StrCpy $0 "$SysDir\cmd.exe"
  IfFileExists $0 +2
    ExpandEnvStrings $0 "%COMSPEC%"
  nsExec::Exec '"$0" /C "$PluginsDir\mybatch.bat"'
  Pop $0 ; Exit code
  SetOutPath $Temp ; Don't hold lock on $PluginsDir
FunctionEnd

Function .onInit
  ReadRegStr $0 HKLM "Software\Software\Microsoft\Windows\CurrentVersion\Uninstall\${UninstId}" "UninstallString"
  ${If} $0 != ""
    !insertmacro UninstallExisting $0 $0 ; https://nsis.sourceforge.io/Auto-uninstall_old_before_installing_new
    ${If} $0 <> 0
      Call RunMyBatch ; Run batch if uninstall old failed
    ${EndIf}
  ${EndIf}
FunctionEnd

Function .onInstFailed
  Call RunMyBatch ; Run batch if install failed
FunctionEnd

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多