Description
This is a long-standing bug that also affects Windows PowerShell.
On Windows, -Credential
can be used to start a process in a new window with a given user identity.
Currently, doing so effectively prevents interactive use of both the caller's window and the new window, because they seem to be competing for keyboard input.
Note: Curiously, if you start powershell.exe
specifically, the problem does not occur; other shells, however - such as pwsh
itself and cmd
- do exhibit the problem.
Update:
- The problem may be related to the
PSReadLine
module, given that unloading it first (Remove-Module PSReadLine
) makes the problem go away - see Bug when launching a new Powershell instance with Start-Process and alternate credentials PSReadLine#288
Steps to reproduce
On Windows (update: problem verified on Windows 10 versions 1809 and 1909 - see (Get-ComputerInfo).WindowsVersion
)
# Enter a different user's credentials (or even your own) when prompted.
Set-Location C:\; Start-Process cmd -Credential (Get-Credential)
Expected behavior
The call should return after having launched the cmd
process and both the calling shell and the cmd
shell in the new window should function normally and independently.
Actual behavior
Typing in either window either has no effect or sometimes makes what was typed show up in the respective other window.
Behavior returns to normal when the new window is closed.
Environment data
PowerShell Core v7.0.0 (7.0.0) on Microsoft Windows 10 Pro (64-bit; Version 1909, OS Build: 18363.720)
Workarounds
-
Use
runas.exe
-
Launch the initial process hidden, non-interactively, and use it as an intermediary to launch an interactive session in a new, visible window; e.g.:
Start-Process -WindowStyle Hidden -Credential (Get-Credential) cmd '/c start cmd' -WorkingDirectory c:\