detect store-installed powershell - fixes #5212

This commit is contained in:
Eugene Pankov 2021-12-23 14:15:48 +01:00
parent d644c299ae
commit 0c601592e3
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -73,21 +73,22 @@ export class WindowsStockShellsProvider extends ShellProvider {
} }
private async getPowerShellPath () { private async getPowerShellPath () {
const ps = 'powershell.exe' for (const name of ['pwsh.exe', 'powershell.exe']) {
if (await promisify(hasbin)(name)) {
if (!await promisify(hasbin)(ps)) { return name
for (const searchPath of [ }
`${process.env.SystemRoot}\\System32\\WindowsPowerShell\\v1.0`, }
`${process.env.SystemRoot}\\System32`, for (const psPath of [
process.env.SystemRoot ?? 'C:\\Windows', `${process.env.USERPROFILE}\\AppData\\Local\\Microsoft\\WindowsApps\\pwsh.exe`,
`${process.env.SystemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,
`${process.env.SystemRoot}\\System32\\powershell.exe`,
(process.env.SystemRoot ?? 'C:\\Windows') + '\\powerhshell.exe',
]) { ]) {
const newPath = path.join(searchPath, ps)
try { try {
await fs.stat(newPath) await fs.stat(psPath)
return newPath return psPath
} catch { } } catch { }
} }
} return 'powershell.exe'
return ps
} }
} }