diff --git a/installers/install.ps1 b/installers/install.ps1 index 12d10e20da..ac5eb4e97d 100644 --- a/installers/install.ps1 +++ b/installers/install.ps1 @@ -147,11 +147,23 @@ function error([string] $msg) Write-Host $msg -ForegroundColor Red } -function setShellOverride { - $parentProcess = Get-WmiObject Win32_Process | Where-Object { $_.ProcessId -eq $PID } - $parentProcessDetails = Get-WmiObject Win32_Process | Where-Object { $_.ProcessId -eq $parentProcess.ParentProcessId } - if ($parentProcessDetails.Name -eq "cmd" -or $parentProcessDetails.Name -eq "cmd.exe") { - [System.Environment]::SetEnvironmentVariable("ACTIVESTATE_CLI_SHELL_OVERRIDE", $parentProcessDetails.Name, "Process") +function setShellOverride +{ + # Walk up the process tree to find cmd.exe + # If we encounter it we set the shell override + $currentPid = $PID + while ($currentPid -ne 0) + { + $process = Get-WmiObject Win32_Process | Where-Object { $_.ProcessId -eq $currentPid } + if (!$process) { break } + + if ($process.Name -eq "cmd" -or $process.Name -eq "cmd.exe") + { + [System.Environment]::SetEnvironmentVariable("ACTIVESTATE_CLI_SHELL_OVERRIDE", "cmd.exe", "Process") + break + } + + $currentPid = $process.ParentProcessId } } @@ -257,6 +269,7 @@ $PSDefaultParameterValues['*:Encoding'] = 'utf8' # Run the installer. $env:ACTIVESTATE_SESSION_TOKEN = $script:SESSION_TOKEN_VALUE setShellOverride +Write-Host $env:ACTIVESTATE_CLI_SHELL_OVERRIDE & $exePath $args --source-installer="install.ps1" $success = $? if (Test-Path env:ACTIVESTATE_SESSION_TOKEN)