Skip to content

Commit

Permalink
- Always deploy to %AppData% if librewolf.exe is in the script's folder
Browse files Browse the repository at this point in the history
- Fix infinite restarts (e.g. when UAC is completely disabled)
  `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA` = `0`
- Consistently format Unelevate()
  • Loading branch information
ltguillaume committed Aug 5, 2023
1 parent 870e4b1 commit 859d714
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions LibreWolf-WinUpdater.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; LibreWolf WinUpdater - https://codeberg.org/ltguillaume/librewolf-winupdater
;@Ahk2Exe-SetFileVersion 1.7.10
;@Ahk2Exe-SetFileVersion 1.7.11

;@Ahk2Exe-Base Unicode 32*
;@Ahk2Exe-SetCompanyName LibreWolf Community
Expand Down Expand Up @@ -78,7 +78,7 @@ CheckArgs()
GetCurrentVersion()
If (ThisUpdaterRunning())
Die(_IsRunningError,, False) ; Don't show this if Scheduled
Unelevate(A_ScriptFullPath, Args, A_ScriptDir)
Unelevate(A_ScriptFullPath, "/Restart " Args, A_ScriptDir)
CheckWriteAccess()
If (SettingTask)
TaskSet()
Expand Down Expand Up @@ -242,9 +242,11 @@ SelfUpdate() {
}

CheckWriteAccess() {
FileAppend,, %IniFile%
If (!ErrorLevel)
Return
If (!FileExist(A_ScriptDir "\" LibreWolfExe)) {
FileAppend,, %IniFile%
If (!ErrorLevel)
Return
}

AppData := A_AppData "\LibreWolf\WinUpdater"

Expand Down Expand Up @@ -730,32 +732,32 @@ TaskSet() {
}
}

Unelevate(prms*) {
If (!A_IsAdmin Or IsPortable Or Scheduled)
Unelevate(Prms*) {
If (!A_IsAdmin Or IsPortable Or Scheduled Or RegExMatch(DllCall("GetCommandLine", "str"), " /Restart(?!\S)"))
Return

; ShellRun(prms*) from AutoHotkey's Installer.ahk
; ShellRun(Prms*) from AutoHotkey's Installer.ahk
Try {
shellWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(_hwnd, 4, 0)
desktop := shellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_hwnd), 1)
if ptlb := ComObjQuery(desktop
, "{4C96BE40-915C-11CF-99D3-00AA004AE837}" ; SID_STopLevelBrowser
, "{000214E2-0000-0000-C000-000000000046}") ; IID_IShellBrowser
{
if DllCall(NumGet(NumGet(ptlb+0)+15*A_PtrSize), "ptr", ptlb, "ptr*", psv:=0) = 0
{
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x20400, IID_IDispatch, "int64"), "int64")
DllCall(NumGet(NumGet(psv+0)+15*A_PtrSize), "ptr", psv
, "uint", 0, "ptr", &IID_IDispatch, "ptr*", pdisp:=0)
shell := ComObj(9,pdisp,1).Application
shell.ShellExecute(prms*)
ObjRelease(psv)
}
ObjRelease(ptlb)
}
ExitApp
ShellWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(_Hwnd, 4, 0)
Desktop := ShellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_Hwnd), 1)
If Ptlb := ComObjQuery(Desktop
, "{4C96BE40-915C-11CF-99D3-00AA004AE837}" ; SID_STopLevelBrowser
, "{000214E2-0000-0000-C000-000000000046}") ; IID_IShellBrowser
{
If DllCall(NumGet(NumGet(Ptlb + 0) + 15 * A_PtrSize), "ptr", Ptlb, "ptr*", Psv := 0) = 0
{
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x20400, IID_IDispatch, "int64"), "int64")
DllCall(NumGet(NumGet(psv+0)+15*A_PtrSize), "ptr", Psv
, "uint", 0, "ptr", &IID_IDispatch, "ptr*", Pdisp := 0)
Shell := ComObj(9, Pdisp, 1).Application
Shell.ShellExecute(Prms*)
ObjRelease(Psv)
}
ObjRelease(Ptlb)
}
ExitApp
} Catch e
Die(_IsElevated)
}

0 comments on commit 859d714

Please sign in to comment.