繁体   English   中英

在安装软件时,如果特定条件为假,如何使用NSIS回退软件安装过程?

[英]when installing the software, if the specific condition is false How to roll back the software installation process using NSIS?

我的要求是使用NSIS安装程序安装软件时,应调用该函数并检查UPS是否已连接到计算机。

如果UPS已连接,它将完成安装过程。

如果未连接UPS电池,则会显示一个消息框,询问“请连接UPS,然后使用“取消”和“重试”按钮重试”。 如果单击“取消”,它将回滚安装过程。

我可以使用以下代码行获取是否已连接UPS:

 System::Call "$INSTDIR\drvutil.dll::IsUPSPresent() i.r0 ?e"

然后,我使用“如果”条件并检查UPS是否已连接

 ${If} $0 = 0

如果条件为假,则需要显示消息框,例如“请连接UPS,然后使用“取消”和“重试”按钮重试”。 如果我单击“ Cancle”,它将回滚安装过程。 并且,如果我连接UPS(或条件为True),则安装应完成。

请帮助我如何实现此逻辑。

以下是我的代码段:

; The stuff to install
Section "UPSTest (required)"

  SectionIn RO

  DetailPrint "Testing UPS"

  SetOutPath $INSTDIR

  ; Give the dll path
  File E:\TestNullSoft\ValidateUPS.exe
  File E:\TestNullSoft\drvutil.dll
  File E:\TestNullSoft\UpsControl.dll
  File E:\TestNullSoft\UpsDevice.dll
  File E:\TestNullSoft\pdcdll.dll

  System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")' ; Tell Windows we trust all .DLLs in this directory

  System::Call "$INSTDIR\drvutil.dll::IsUPSPresent() i.r0 ?e"
  Pop $1
  MessageBox MB_OK "Return value = $0, lasterr = $1"
  ; In the below line If the return value is 0("false"), That means UPS is not connected to the computer
   ${If} $0 = 0
   ; Here I need to show the Messagebox like "Please connect the UPS and try again with "Cancel" and "Retry" buttons"
   ; If I click on "Cancle", It should Roll back the installation process.

  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\NSIS_UPSTest "Install_Dir" "$INSTDIR"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "DisplayName" "NSIS UPSTest"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "NoRepair" 1
  WriteUninstaller "uninstall.exe"

SectionEnd

请提供您对此的意见。

无需尝试回退部分安装,您只需将.DLL放在一个临时目录中,然后在开始安装文件之前在其中进行检查:

!include LogicLib.nsh

Section
InitPluginsDir
SetOutPath $PluginsDir
File "something\mydll.dll"
SetOutPath $Temp ; Don't hold the lock on $PluginsDir
System::Call 'KERNEL32::AddDllDirectory(w "$PluginsDir")' 

retry:
System::Call '$PluginsDir\mydll.dll::IsUPSPresentDummyFunction(i 0 r0)i.r0?e' ; Fake a return FALSE system call for this example
Pop $1 ; LastError
${If} $0 = 0
    MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Blah blah UPS blah blah error $1" IDRETRY retry
    Abort "UPS required!" ; You can replace this with Quit if you want
${EndIf}

SetOutPath $InstDir
WriteUninstaller "$InstDir\uninstall.exe"
File "something\myapp.exe"
...
SectionEnd

安装程序退出时,$ PluginsDir将被自动删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM