Skip to content

Start-Process fails to launch new powershell.exe instance with -UseNewEnvironment switch #3545

Closed

Description

Steps to reproduce

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.

Windows PowerShell:

Start-Process -FilePath C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoNewWindow -UseNewEnvironment

PowerShell Core (Debug build):

Start-Process -FilePath .\powershell.exe -NoNewWindow -UseNewEnvironment

Expected behavior

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

Activity

  1. added
    WG-Interactive-Console
    Up-for-Grabs
    on Apr 12, 2017
  2. iSazonov commented on Apr 17, 2017

    @iSazonov
    Collaborator

    It seems we have two problems.

    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.

  3. mklement0 commented on Aug 7, 2017

    @mklement0
    Contributor

    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):

    ALLUSERSPROFILE
    APPDATA
    CommonProgramFiles
    CommonProgramFiles(x86)
    CommonProgramW6432
    COMPUTERNAME
    HOMEDRIVE
    HOMEPATH
    LOCALAPPDATA
    LOGONSERVER
    ProgramData
    ProgramFiles
    ProgramFiles(x86)
    ProgramW6432
    PUBLIC
    SESSIONNAME
    SystemDrive
    SystemRoot
    USERDOMAIN
    USERDOMAIN_ROAMINGPROFILE
    USERPROFILE
    

    Ilya (@iSazonov):

    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.)

  4. GeeLaw commented on Jun 18, 2018

    @GeeLaw

    On Windows, you should use CreateEnvironmentBlock function to create a complete block of environment variables for a specified user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedUp-for-GrabsWG-Interactive-Console

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions