PowerShell using Sytem.Diagnostics.ProcessStartInfo ExitCode -1073741502

Horacio 1 Reputation point
2020-10-02T19:46:04.343+00:00

I have a task that is running with NETWORK SERVICE account that is calling a ps1, the ps1 is calling System.Diagnostics.ProcessStartInfo and System.Diagnostics.Process with credentials and always have the same exit Code -1073741502 and never calls the StartProcessDummy.ps1 , the arguments for the actions in the task are: -Version "5.0" -Noninteractive -Noprofile -WindowStyle "Hidden" -Command "& 'C:\Dev\StartProcessInfo.ps1'", the settings of the task:
29905-image.png

And the code:

try {  
  
Start-Transcript -Path "$($PSScriptRoot)\StartProcess.log"  
  
$user = "DOMAIN\userName"  
$pswd = "Password" | ConvertTo-SecureString -AsPlainText -Force  
  
  
$credentials =  New-Object System.Management.Automation.PSCredential -ArgumentList $user,$pswd  
  
$workingDirectory = $PSScriptRoot  
  
$commandlet = "$($PSScriptRoot)\StartProcessDummy.ps1"  
  
$argList = ' -Command ""& '+ $commandlet + '""'  
  
  
ProcessStartInfo  
 $psi = New-Object System.Diagnostics.ProcessStartInfo -Prop @{  
    RedirectStandardError = $True  
    RedirectStandardOutput = $True  
    UseShellExecute = $False  
    UserName = $credentials.GetNetworkCredential().UserName  
    Domain = $credentials.GetNetworkCredential().Domain  
    Password = $credentials.Password  
    WorkingDirectory = $PSScriptRoot  
    FileName = "powershell.exe"  
    Arguments = $argList  
    WindowStyle = "Hidden"  
}  
$whosthis=whoami  
Write-Host "WhoAmi: $whosthis"  
Write-Host "ProcessStartInfo:"  
Write-Host "*******************************************************************"  
#$psi | Format-List -Property * | Out-String  
Write-Host  
Write-Host  
  
$p = New-Object System.Diagnostics.Process  
    $p.StartInfo = $psi  
    $p.Start() | Out-Null  
    $p.WaitForExit()  
  
Write-Host "Process:"     
Write-Host "*******************************************************************"  
#$p | Format-List -Property * | Out-String     
  
$stdout = $p.StandardOutput.ReadToEnd()  
$stderr = $p.StandardError.ReadToEnd()  
Write-Host "stdout: $stdout"  
Write-Host "stderr: $stderr"  
Write-Host "exit code: " + $p.ExitCode  
  
}  
catch {  
    $_ | format-list -force | Out-String   
    throw  
}  
finally{  
Stop-Transcript  
}  
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bill Stewart 186 Reputation points
    2020-11-10T23:27:08.9+00:00

    When we translate signed integer -1073741502 to its unsigned 64-bit value, we get 3221225794 (hexadecimal C0000142).

    0xC0000142 is the NTSTATUS value STATUS_DLL_INIT_FAILED - see https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55 - description is this:

    {DLL Initialization Failed} Initialization of the dynamic link library <filename> failed. The process is terminating abnormally.

    Not sure what process you are starting but hopefully this information can help you with further troubleshooting.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.