你好,我正在重构一个旧的安装脚本,并遇到UAC插件创建的问题。由于!insertmacro Init "installer"
.onInit
运行两次。 !insertmacro Init "uninstaller"
和un.onInit
函数也是如此。NSIS安装程序.onInit和un.onInit由于UAC运行两次因为UAC
因此,安装程序和卸载程序运行两次,这不是我想要的行为。 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
@Anders我在推动并尝试几件事情,而我输入这个。对不起,如果它现在有所不同。考虑链接中我正在运行的当前代码中的代码。另外,我将它构建在Windows 2008 64位服务器上,并在Windows 10机器(也是64位)上测试安装过程。 – Gooey
@Anders我已经撤消了一些我的实验性修改并推送了它们。我现在不会推动它,因为当人们看着它时,它确实令人困惑。 – Gooey