Skip to content

Commit

Permalink
Walk process tree
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Oct 29, 2024
1 parent f40316e commit 7bc6706
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions installers/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7bc6706

Please sign in to comment.