question

Horacio-3376 avatar image
0 Votes"
Horacio-3376 asked VardanHarutyunyan-4485 commented

PowerShell using Sytem.Diagnostics.ProcessStartInfo ExitCode -1073741502

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-server-powershell
image.png (12.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

BillStewart avatar image
0 Votes"
BillStewart answered VardanHarutyunyan-4485 commented

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://docs.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.





· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Found following

https://support.microsoft.com/en-us/topic/-0xc0000142-or-1073741502-stop-error-when-many-powershell-scripts-call-the-console-write-method-or-when-you-try-to-start-many-console-applications-on-a-powershell-console-in-windows-7-or-in-windows-server-2008-r2-19f475a2-cbe9-c463-a2b4-b7fe7a1d236d

This issue is caused by an error in the Microsoft.powershell.consolehost.dll file. When a Windows PowerShell script calls the Console.Write method, or when you run an executable file for an application from a Windows PowerShell session, values are written into the PowerShell console. Additionally, a corresponding console handle is created. When many console handles are created, the console handles leak, and the issue that is described in the "Symptoms" section occurs.

Do you have any info about it?

Thank you

0 Votes 0 ·