X Tutup
The Wayback Machine - https://web.archive.org/web/20230329061736/https://github.com/PowerShell/PowerShell/issues/19411
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't retrieve exitCode (oer exitTime) from a process started with Start-Process -PassTru -Credentials #19411

Open
5 tasks done
jjsmeets opened this issue Mar 27, 2023 · 1 comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@jjsmeets
Copy link

Prerequisites

Steps to reproduce

$Process1 =Start-Process pwsh.exe -PassThru -credential $Credentials -ArgumentList "-file $Script_Str" -Wait
$Process2 =Start-Process pwsh.exe -PassThru -ArgumentList "-file $Script_Str" -Wait
Write-host "retrieved process1 exit info $($Process1.ExitCode) $($Process1.ExitTime)"
Write-host "retrieved process2 exit info $($Process2.ExitCode) $($Process2.ExitTime)"

Expected behavior

The exitCode  should be the same in both write-host output lines

Actual behavior

Output is:
retrieved process1 exit info  
retrieved process2 exit info 100 03/27/2023 19:36:21

Error details

No response

Environment data

�[32;1mName                          �[0m�[32;1m Value�[0m
�[32;1m----                          �[0m �[32;1m-----�[0m
PSVersion                      7.4.0-preview.2
PSEdition                      Core
GitCommitId                    7.4.0-preview.2
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

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

@jjsmeets jjsmeets added the Needs-Triage The issue is new and needs to be triaged by a work group. label Mar 27, 2023
@jborean93
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup