如何从安装程序复制文件而不进行安装

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

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

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

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

batch-file windows-installer nsis
1个回答
0
投票

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
© www.soinside.com 2019 - 2024. All rights reserved.