由于 UAC,NSIS 安装程序 .onInit 和 un.onInit 运行两次 [英] NSIS installer .onInit and un.onInit run twice because of UAC

查看:53
本文介绍了由于 UAC,NSIS 安装程序 .onInit 和 un.onInit 运行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在重构一个旧的安装脚本并遇到了 UAC 插件创建的问题.由于 !insertmacro Init "installer".onInit 运行了两次.!insertmacro Init "uninstaller"un.onInit 函数也是如此.

Hello I am refactoring an old install script and run into the issue that the UAC plugin creates. Because of the !insertmacro Init "installer" the .onInit runs twice. The same goes for !insertmacro Init "uninstaller" and the un.onInit function.

因此,安装程序和卸载程序运行两次,这不是我想要的行为.我读到 UAC 创建了一个内部具有提升权限的进程,例如,当它接触C:/ 驱动器时,这是必需的,但外部进程也运行安装程序.

Because of this, the installer and the uninstaller run twice which is not the behavior I want. I have read that the UAC creates an inner process with elevated permissions, which IS required as it touches the C:/ drive for example, but the outer process also runs the installer.

因为安装脚本很长,所以我只粘贴了 .onInit 函数.可以找到整个 .nsi 脚本 这里.

Because the install script is quite long I only paste the .onInit function. The whole .nsi script can be found here.

!insertmacro 注释掉该行可确保 .onInit 函数运行一次,但不再运行安装程序.那么我怎样才能让安装程序和卸载程序只运行一次,并具有正确的(管理员)权限?

Commenting out the line with the !insertmacro makes sure the .onInit function runs once, but does not run the installer anymore. So how can I make the installer and the uninstaller only run once, with the right (admin) permissions?

我感谢任何建议或回答:)

I appreciate any suggestion or answer :)

Function .onInit
MessageBox MB_OK "In .onInit"
  SetShellVarContext all

  !insertmacro Init "installer"

  System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Tribler") i .r1 ?e'

  Pop $R0
  StrCmp $R0 0 checkinst

  MessageBox MB_OK "The installer is already running."
  Abort

  checkinst:
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
  StrCmp $R0 "" done
  IfFileExists $R0 showuninstdialog done

  showuninstdialog:
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT} is already installed. $\n$\nClick `OK` to remove the previous version or `Cancel` to cancel this upgrade." /SD IDCANCEL IDOK uninst
  Abort

  uninst:
    ClearErrors
    ; Laurens (2016-03-29): Retrieve the uninstallString stored in the register. Do NOT use $INSTDIR as this points to the current $INSTDIR var of the INSTALLER, 
    ; which is the default location at this point.
    ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
 MessageBox MB_OK "$R0"
    ExecWait '"$R0"' ;Do not copy the uninstaller to a temp file
    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
    StrCmp $R0 "" done
    Abort
  done:

FunctionEnd

推荐答案

您链接到的代码(至少在我查看时)调用了 !insertmacro UAC_RunElevated!insertmacro Init.onInit 中的安装程序" 所以难怪它运行了多次.调用 !insertmacro UAC_RunElevated 后,您必须始终检查 $0,因为您可能必须根据其值调用 Quit

The code you linked to (at least when I looked at it) called both !insertmacro UAC_RunElevated and !insertmacro Init "installer" in .onInit so no wonder it ran multiple times. After calling !insertmacro UAC_RunElevated you must always check $0 because you might have to call Quit depending on its value!

我假设 Init 宏是我写的(?)所以它应该可以正常工作;)

I assume that Init macro is something I wrote(?) so it should work correctly ;)

我个人建议您放弃完成页面上的运行复选框,然后您可能根本不必使用 UAC 插件...

I would personally recommend that you sacrifice the run checkbox on the finish page and then you probably don't have to use the UAC plug-in at all...

这篇关于由于 UAC,NSIS 安装程序 .onInit 和 un.onInit 运行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆