|
38 | 38 | !else
|
39 | 39 | StrCpy $CmdPath "$SYSDIR\cmd.exe"
|
40 | 40 | 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" |
43 | 42 | !insertmacro IS_POWERSHELL_AVAILABLE
|
44 | 43 | !insertmacro _CHECK_APP_RUNNING
|
45 | 44 | !endif
|
46 | 45 | !macroend
|
47 | 46 |
|
48 | 47 | !macro IS_POWERSHELL_AVAILABLE
|
49 | 48 | 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 }"` |
52 | 51 | Pop $0 # Return code (0 = success, other = error)
|
53 | 52 |
|
54 | 53 | ${if} $0 == 0
|
55 | 54 | # 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 }"` |
57 | 56 | Pop $0
|
58 |
| - ${else} |
| 57 | + ${endIf} |
| 58 | + |
| 59 | + ${if} $0 != 0 |
59 | 60 | StrCpy $0 1
|
60 | 61 | ${endIf}
|
61 | 62 |
|
|
64 | 65 |
|
65 | 66 | !macro FIND_PROCESS _FILE _RETURN
|
66 | 67 | ${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 }"` |
68 | 69 | Pop ${_RETURN}
|
69 | 70 | ${else}
|
70 | 71 | !ifdef INSTALL_MODE_PER_ALL_USERS
|
|
90 | 91 | ${endIf}
|
91 | 92 |
|
92 | 93 | ${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 }"` |
94 | 95 | ${else}
|
95 | 96 | !ifdef INSTALL_MODE_PER_ALL_USERS
|
96 | 97 | nsExec::Exec `taskkill /IM "${_FILE}" /FI "PID ne $pid"`
|
|
0 commit comments