简体   繁体   English

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

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

My requirement is when installing the software using NSIS installer, it should call the function and check if the UPS is connected to the computer or not. 我的要求是使用NSIS安装程序安装软件时,应调用该函数并检查UPS是否已连接到计算机。

If the UPS is connect it would complete the installation process. 如果UPS已连接,它将完成安装过程。

If the UPS battery is not connected it would show a message box asking "Please connect the UPS and try again with "Cancel" and "Retry" buttons". 如果未连接UPS电池,则会显示一个消息框,询问“请连接UPS,然后使用“取消”和“重试”按钮重试”。 If "cancel" is clicked, it would Roll back the installation process. 如果单击“取消”,它将回滚安装过程。

I am able to get if the UPS is connected or not using the below line of code: 我可以使用以下代码行获取是否已连接UPS:

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

Then I am using the "If" condition and checking if the UPS is connected or not 然后,我使用“如果”条件并检查UPS是否已连接

 ${If} $0 = 0

If the condition is false, I need to show the Messagebox like "Please connect the UPS and try again with "Cancel" and "Retry" buttons". 如果条件为假,则需要显示消息框,例如“请连接UPS,然后使用“取消”和“重试”按钮重试”。 If I click on "Cancle", It should Roll back the installation process. 如果我单击“ Cancle”,它将回滚安装过程。 And If i connect the UPS (or the condition is True) then installation should complete. 并且,如果我连接UPS(或条件为True),则安装应完成。

Please help me how to implement this logic. 请帮助我如何实现此逻辑。

Below is my code snippet: 以下是我的代码段:

; 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

Please provide your inputs on this. 请提供您对此的意见。

Instead of trying to roll back a partial install you can just put the .DLL in a temporary directory and do the check there just before you start installing files: 无需尝试回退部分安装,您只需将.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 is deleted automatically when the installer exits. 安装程序退出时,$ PluginsDir将被自动删除。

暂无
暂无

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

相关问题 使用NSIS安装软件时,如何设置进度条文本? - When installing the software using NSIS how to set the progress bar text? 使用NSIS安装软件时如何更改用户帐户控制屏幕文本 - How to change the User Account Control screen text when installing the software using NSIS 使用NSIS安装软件时,如何通过从目标文件夹获取路径来检查驱动器中的空间 - How to check the space in the drive by taking the path from the Destination Folder When installing the software using NSIS 安装使用NSIS开发的软件时,如果在服务器操作系统中安装,应如何抛出弹出消息 - When installing the software that was developed using NSIS, how should I throw a pop-up message if installing in server operating systems 如何使用NSIS安装较新版本的软件之前先卸载较旧版本的软件 - How to uninstall older version of the software before installing the newer version using NSIS 如何检查NSIS中安装的软件? - how to check software installed in NSIS? 使用 NSIS 创建和控制服务安装应用程序时安装失败 - Installation is failing when installing the application using NSIS to create and control the service NSIS:无法在Windows 7上写入注册表(HKLM \\ Software \\ ...) - NSIS: Unable to write to registry (HKLM\Software\…) on Windows 7 NSIS-检测可用的驱动程序,并让用户决定在哪里安装特定文件(软件许可) - NSIS - Detect drivers available and let the user decide where to install an specific file (the license of the software) 如何检查NSIS中特定端口上运行的进程 - How to check the process running on specific port in NSIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM