When I execute the following code:
$creds = Get-Credential -UserName other -Message none
# answering the creds dialogue with correct password here
Start-Process C:\Windows\system32\cmd.exe -Credential $credsa cmd windows opens (looks completely normal and I can change settings...) but I cannot type anything into the window. Independent of whether it is a normal user or an admin account and the powershell itself is run as normal user or as admin. Except when the Powershell is run as System (via Sysinternal's psexec): then I get the following error:
Start-Process : This command cannot be run due to the error: Access denied
At line:1 char:1
+ Start-Process C:\Windows\system32\cmd.exe -Credential $creds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommandI combined this with cmd.exe and powershell instead of the whole cmd-path and added the -NoNewWindow parameter but nothing of that makes a difference (opens a new window despite the -NoNewWindow). When runnnig "normal" programs like notepad everything works as expected - also when I run e.g. runas /user:other cmd. I currently only have Windows [Version 10.0.17134.165] to test and I am not sure if this is the same on other versions but I think it is Windows 10 specific (?).
Another killjoy flaw in Powershell or am I missing something?
1 Answer
There is definitely something strange going on here: both the starting PowerShell window and the new command prompt seem to stop accepting input after the new process is started. After switching between the two windows a bit, the command prompt temporarily starts accepting keyboard input, but then gets stuck again after executing a command.
You can work around this issue by using the .NET Framework's Process.Start method directly:
$creds = Get-Credential -UserName 'theUser' -Message ' '
[System.Diagnostics.Process]::Start('cmd', $creds.UserName, $creds.Password, '')The resulting command prompt acts normally, as does the existing PowerShell window. If you don't want PowerShell to output some info about the new process, tack | Out-Null onto the end of the second line.