【发布时间】:2016-08-29 15:43:20
【问题描述】:
您好,我正在重构一个旧的安装脚本并遇到了 UAC 插件创建的问题。由于!insertmacro Init "installer",.onInit 运行了两次。 !insertmacro Init "uninstaller" 和 un.onInit 函数也是如此。
因此,安装程序和卸载程序运行两次,这不是我想要的行为。 I have read that the UAC creates an inner process with elevated permissions,这是必需的,因为它涉及 C:/ 驱动器,但外部进程也运行安装程序。
由于安装脚本很长,我只粘贴了.onInit 函数。整个.nsi 脚本可以在here 找到。
用!insertmacro 注释掉该行可确保.onInit 函数运行一次,但不再运行安装程序。那么如何让安装程序和卸载程序只运行一次,并具有正确的(管理员)权限?
感谢任何建议或回答:)
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
【问题讨论】:
-
您在此处粘贴的 .onInit 代码与您链接的代码不匹配!您链接到的代码有一个明显的问题,如果不测试自己,无法真正判断粘贴在这里的代码是否有问题,但在您澄清我应该测试的代码之前,我不会这样做。有一些关于使用的 NSIS/UAC 插件/Windows 版本的信息也很好......
-
@Anders 我在键入此内容时正在推动和尝试几件事。抱歉,如果现在有所不同。将链接中的代码视为我正在运行的当前代码。另外,我正在 Windows 2008 64 位服务器上构建它,并在 Windows 10 机器上测试安装过程,也是 64 位。
-
@Anders 我已经撤消了一些实验性更改并推送了它们。我暂时不会推动它,因为当人们看到它时确实会让人感到困惑。
标签: installation nsis uninstallation