Start-Process -PassThru -Credentials -Wait was not working prior to powershell 7.4 preview 2, but now works
but there is still an error with the exitCode.
This also is a problem when not using -Wait as part of Start-Process (but using $p.waitForExit() instead)
-Credentials are for another user!
(same problem when retrieving ExitTime
The text was updated successfully, but these errors were encountered:
As mentioned in #17033 (comment), the underlying code is unable to give dotnet the full access token so the retrieved manually from GetProcessById is heavily restricted in what it can do. Now that dotnet has just merged in dotnet/runtime#82662 it should be possible to remove the manual PInvoke call to CreateProcessWithLogon and use dotnet itself to spawn the new process and the resulting Process object returned will have full access to do what you are looking for.
Prerequisites
Steps to reproduce
$Process1 =Start-Process pwsh.exe -PassThru -credential $Credentials -ArgumentList "-file $Script_Str" -Wait$($Process1.ExitCode) $ ($Process1.ExitTime)"$($Process2.ExitCode) $ ($Process2.ExitTime)"
$Process2 =Start-Process pwsh.exe -PassThru -ArgumentList "-file $Script_Str" -Wait
Write-host "retrieved process1 exit info
Write-host "retrieved process2 exit info
Expected behavior
The exitCode should be the same in both write-host output linesActual behavior
Error details
No response
Environment data
Visuals
Start-Process -PassThru -Credentials -Wait was not working prior to powershell 7.4 preview 2, but now works
but there is still an error with the exitCode.
This also is a problem when not using -Wait as part of Start-Process (but using $p.waitForExit() instead)
-Credentials are for another user!
(same problem when retrieving ExitTime
The text was updated successfully, but these errors were encountered: