fix(desktop): Windows updates no longer fail when one app process is left running #25831
Showing 2 changed files with 29 additions and 9 deletions.
x
@@ -14,11 +14,31 @@
+index 7d08e55f5ddf70e51ebd965803d001561bca6d71..4977fcfc35ba32e039f1211ca0ed05ccd20f38f1 100644
-@@ -103,6 +103,9 @@
- !macroend
-
+@@ -63,7 +63,8 @@
+
+ !macro FIND_PROCESS _FILE _RETURN
+ ${if} $IsPowerShellAvailable == 0
+- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "if ((Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
++ # @() keeps .Count defined for one process on PowerShell 5.1 (electron-builder#10454); skip our own PID
++ nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "if (@(Get-CimInstance -ClassName Win32_Process | ? {$$_.ProcessId -ne $pid -and $$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
+ Pop ${_RETURN}
+ ${else}
+ !ifdef INSTALL_MODE_PER_ALL_USERS
+@@ -91,7 +92,7 @@
+ ${endIf}
+
+ ${if} $IsPowerShellAvailable == 0
+- nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"`
++ nsExec::Exec `"$PowerShellPath" -NoProfile -NonInteractive -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.ProcessId -ne $pid -and $$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"`
+ ${else}
+ !ifdef INSTALL_MODE_PER_ALL_USERS
+ nsExec::Exec `taskkill /IM "${_FILE}" /FI "PID ne $pid"`
+@@ -103,6 +104,9 @@