Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walk process tree to find cmd #3572

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 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", $process.Name, "Process")
break
}

$currentPid = $process.ParentProcessId
}
}

Expand Down
Loading