You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Start-Process fails to launch new powershell.exe instance with -UseNewEnvironment switch #3545
I dont know why would anyone do this, but here it goes: you cannot launch another powershell.exe using Start-Process cmdlet with -UseNewEnvironment switch.
A new instance of powershell.exe console should start.
Actual behavior
Windows PowerShell outputs error and dies:
Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.
PowerShell Core (Debug build) outputs more errors + assert message and dies:
Error resolving full path []
Error resolving full path []
PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
The shell cannot be started. A failure occurred during initialization:
ASSERT: caller makes sure it's not null or empty
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 5.1.14409.1005
PSEdition Desktop
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
BuildVersion 10.0.14409.1005
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1>$PSVersionTable
Name Value
---------
PSVersion 6.0.0-alpha
GitCommitId v6.0.0-alpha.18-9-g8d4db01a5d4b5dcd981ef216d3d7f24b484c7c60-dirty
WSManStackVersion 3.0
CLRVersion
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
BuildVersion 3.0.0.0
PSRemotingProtocolVersion 2.3
PSEdition Core
SerializationVersion 1.1.0.1
Reacted by Michael Klement, Retia, 初绎, Mazen Besher and David Sherret
Error resolving full path []
The shell cannot be started. A failure occurred during initialization:
ASSERT: caller makes sure it's not null or empty
The first, I fixed by restore "ProgramFiles" and "ProgramFiles(X86)"environment variables for subprocess.
I don't understand how PowerShell use it in start time and perhaps my fix is not in right place.
The second problem is that new PowerShell process get wrong cursor position in the same console windows. I belive we should open new trackig Issue.
What -UseNewEnvironment appears to be doing is to define only the variables that are explicitly defined, as displayed in System Properties (sysdm.cpl) (with user-level definitions taking precedence over system-level ones, as usual).
However, the implicitly defined environment variables are missing, among them the two Ilya (@iSazonov) mentions.
Additionally, $env:USERNAME contains SYSTEM, because it is explicitly defined as a system-level variable, but not at the user level (where it is normally implicitly defined to reflect the current user).
List of missing, normally implicitly defined environment variables (I don't know what mechanism defines them by default):
The second problem is that new PowerShell process get wrong cursor position in the same console windows. I belive we should open new trackig Issue.
I think that's an artifact of using -NoNewWindow without -Wait, which makes the output appear asynchronously.
(Normally, if you wanted to run a console app synchronously in the same window you wouldn't use Start-Process at all; my guess is that Giorgi Chakhidze (@0xfeeddeadbeef) only included -NoNewWindow so that the error message would show; without it, you'd just see a new window opening and closing right away.)
Activity
iSazonov commentedon Apr 17, 2017
It seems we have two problems.
The first, I fixed by restore "ProgramFiles" and "ProgramFiles(X86)"environment variables for subprocess.
I don't understand how PowerShell use it in start time and perhaps my fix is not in right place.
The second problem is that new PowerShell process get wrong cursor position in the same console windows. I belive we should open new trackig Issue.
mklement0 commentedon Aug 7, 2017
What
-UseNewEnvironmentappears to be doing is to define only the variables that are explicitly defined, as displayed in System Properties (sysdm.cpl) (with user-level definitions taking precedence over system-level ones, as usual).However, the implicitly defined environment variables are missing, among them the two Ilya (@iSazonov) mentions.
Additionally,
$env:USERNAMEcontainsSYSTEM, because it is explicitly defined as a system-level variable, but not at the user level (where it is normally implicitly defined to reflect the current user).List of missing, normally implicitly defined environment variables (I don't know what mechanism defines them by default):
Ilya (@iSazonov):
I think that's an artifact of using
-NoNewWindowwithout-Wait, which makes the output appear asynchronously.(Normally, if you wanted to run a console app synchronously in the same window you wouldn't use
Start-Processat all; my guess is that Giorgi Chakhidze (@0xfeeddeadbeef) only included-NoNewWindowso that the error message would show; without it, you'd just see a new window opening and closing right away.)GeeLaw commentedon Jun 18, 2018
On Windows, you should use
CreateEnvironmentBlockfunction to create a complete block of environment variables for a specified user.fix(subprocess): add logon-synthesized variables to Windows allow-list
feat(subprocess): use CreateEnvironmentBlock on Windows instead of al…