Skip to content

Commit 6fb2de4

Browse files
committed
fixup! feat(nsis): terminate only processes running in installation folder
1 parent 77b294b commit 6fb2de4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,25 @@
3838
!else
3939
StrCpy $CmdPath "$SYSDIR\cmd.exe"
4040
StrCpy $FindPath "$SYSDIR\find.exe"
41-
StrCpy $PowerShellPath "pwsh" ; PowerShell Core (7+)
42-
# StrCpy $PowerShellPath "$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" ; actually broken with PowerShell 5.1 (and below), because some Paths are empty.
41+
StrCpy $PowerShellPath "$SYSDIR\WindowsPowerShell\v1.0\powershell.exe"
4342
!insertmacro IS_POWERSHELL_AVAILABLE
4443
!insertmacro _CHECK_APP_RUNNING
4544
!endif
4645
!macroend
4746

4847
!macro IS_POWERSHELL_AVAILABLE
4948
Var /GLOBAL IsPowerShellAvailable ; 0 = available, 1 = not available
50-
# Try running PowerShell with a simple command
51-
nsExec::Exec `"$PowerShellPath" -Command "exit 0"`
49+
# Try running PowerShell with a simple command to check if it's available
50+
nsExec::Exec `"$PowerShellPath" -C "if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"`
5251
Pop $0 # Return code (0 = success, other = error)
5352

5453
${if} $0 == 0
5554
# PowerShell is available, check if it's not blocked by policies
56-
nsExec::Exec `"$PowerShellPath" -Command "if ((Get-ExecutionPolicy -Scope Process) -eq 'Restricted') { exit 1 } else { exit 0 }"`
55+
nsExec::Exec `"$PowerShellPath" -C "if ((Get-ExecutionPolicy -Scope Process) -eq 'Restricted') { exit 1 } else { exit 0 }"`
5756
Pop $0
58-
${else}
57+
${endIf}
58+
59+
${if} $0 != 0
5960
StrCpy $0 1
6061
${endIf}
6162

@@ -64,7 +65,7 @@
6465

6566
!macro FIND_PROCESS _FILE _RETURN
6667
${if} $IsPowerShellAvailable == 0
67-
nsExec::Exec `"$PowerShellPath" -C "if ((Get-Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
68+
nsExec::Exec `"$PowerShellPath" -C "if ((Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"`
6869
Pop ${_RETURN}
6970
${else}
7071
!ifdef INSTALL_MODE_PER_ALL_USERS
@@ -90,7 +91,7 @@
9091
${endIf}
9192

9293
${if} $IsPowerShellAvailable == 0
93-
nsExec::Exec `"$PowerShellPath" -Command "Get-Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | Stop-Process $0"`
94+
nsExec::Exec `"$PowerShellPath" -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"`
9495
${else}
9596
!ifdef INSTALL_MODE_PER_ALL_USERS
9697
nsExec::Exec `taskkill /IM "${_FILE}" /FI "PID ne $pid"`

0 commit comments

Comments
 (0)