From 7bc67060080b451ffda1c68076ea8c476553498c Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Tue, 29 Oct 2024 11:18:25 -0700 Subject: [PATCH 1/4] Walk process tree --- installers/install.ps1 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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) From 31b9182a9bbf07c1b8ab3efdc9cf5999c807760c Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Tue, 29 Oct 2024 11:41:21 -0700 Subject: [PATCH 2/4] Debug script --- installers/install.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installers/install.ps1 b/installers/install.ps1 index ac5eb4e97d..4c75fdb191 100644 --- a/installers/install.ps1 +++ b/installers/install.ps1 @@ -151,15 +151,17 @@ function setShellOverride { # Walk up the process tree to find cmd.exe # If we encounter it we set the shell override + Write-Host "Walking up the process tree to find cmd.exe" $currentPid = $PID while ($currentPid -ne 0) { $process = Get-WmiObject Win32_Process | Where-Object { $_.ProcessId -eq $currentPid } if (!$process) { break } + Write-Host "Checking process $($process.Name) with PID $($process.ProcessId)" if ($process.Name -eq "cmd" -or $process.Name -eq "cmd.exe") { - [System.Environment]::SetEnvironmentVariable("ACTIVESTATE_CLI_SHELL_OVERRIDE", "cmd.exe", "Process") + [System.Environment]::SetEnvironmentVariable("ACTIVESTATE_CLI_SHELL_OVERRIDE", $process.Name, "Process") break } From aaf957b3f9c49558b8f14eb3bb857ed143e65ce9 Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Tue, 29 Oct 2024 11:41:49 -0700 Subject: [PATCH 3/4] More debugging --- installers/install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installers/install.ps1 b/installers/install.ps1 index 4c75fdb191..5024d1ee66 100644 --- a/installers/install.ps1 +++ b/installers/install.ps1 @@ -271,7 +271,7 @@ $PSDefaultParameterValues['*:Encoding'] = 'utf8' # Run the installer. $env:ACTIVESTATE_SESSION_TOKEN = $script:SESSION_TOKEN_VALUE setShellOverride -Write-Host $env:ACTIVESTATE_CLI_SHELL_OVERRIDE +Write-Host "Shell override: $env:ACTIVESTATE_CLI_SHELL_OVERRIDE" & $exePath $args --source-installer="install.ps1" $success = $? if (Test-Path env:ACTIVESTATE_SESSION_TOKEN) From 986f378151ec1cccf96fabbe5585e2ec6e40bcce Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Tue, 29 Oct 2024 12:48:06 -0700 Subject: [PATCH 4/4] Remove debug prints --- installers/install.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/installers/install.ps1 b/installers/install.ps1 index 5024d1ee66..3c8dceda26 100644 --- a/installers/install.ps1 +++ b/installers/install.ps1 @@ -151,14 +151,12 @@ function setShellOverride { # Walk up the process tree to find cmd.exe # If we encounter it we set the shell override - Write-Host "Walking up the process tree to find cmd.exe" $currentPid = $PID while ($currentPid -ne 0) { $process = Get-WmiObject Win32_Process | Where-Object { $_.ProcessId -eq $currentPid } if (!$process) { break } - Write-Host "Checking process $($process.Name) with PID $($process.ProcessId)" if ($process.Name -eq "cmd" -or $process.Name -eq "cmd.exe") { [System.Environment]::SetEnvironmentVariable("ACTIVESTATE_CLI_SHELL_OVERRIDE", $process.Name, "Process") @@ -271,7 +269,6 @@ $PSDefaultParameterValues['*:Encoding'] = 'utf8' # Run the installer. $env:ACTIVESTATE_SESSION_TOKEN = $script:SESSION_TOKEN_VALUE setShellOverride -Write-Host "Shell override: $env:ACTIVESTATE_CLI_SHELL_OVERRIDE" & $exePath $args --source-installer="install.ps1" $success = $? if (Test-Path env:ACTIVESTATE_SESSION_TOKEN)