你好,我正在重構一箇舊的安裝腳本,並遇到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