Title: Launching `pwsh.exe` without a console (`DETACHED_PROCESS`) results in quiet startup failure · Issue #28383 · PowerShell/PowerShell · GitHub
Open Graph Title: Launching `pwsh.exe` without a console (`DETACHED_PROCESS`) results in quiet startup failure · Issue #28383 · PowerShell/PowerShell
X Title: Launching `pwsh.exe` without a console (`DETACHED_PROCESS`) results in quiet startup failure · Issue #28383 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28383
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Launching `pwsh.exe` without a console (`DETACHED_PROCESS`) results in quiet startup failure","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nLaunching a process with the `DETACHED_PROCESS` flag of the WinAPI `CreateProcess()` function by design does so without a console, even for console-subsystem applications.\n\nHowever, `pwsh.exe` assumes the presence of a console and _quietly aborts_ if it cannot find one: exit code `0` is reported, and no WER (Windows Error Reporting) event is recorded in the Windows Application event log.\n\nNote:\n\n* SCM, the Windows Service Control Manager, is an example of a component that starts (service) executables with `DETACHED_PROCESS`; while using `pwsh.exe` as a service executable is not a common use case, it _is_ possible to implement a service via a `.ps1` script passed to `pwsh.exe -File` - see [this Stack Overflow post](https://stackoverflow.com/a/80012322/45375).\n\n* There are two ways to fix this problem:\n\n * Report a nonzero exit code and log a WER event with a specific error message - this is what the repro below assumes.\n \n * Alternatively, allow PowerShell to run without a console: _infer_ non-interactive mode in the absence of a console and prevent attempts to access console-specific features in a controlled manner (note that the `-noninteractive` CLI option does _not_ currently do that).\n\n* The following repro code requires .NET 11+ / at least a PowerShell 7.7 preview version, due to use of the new `.StartDetached` property of `ProcessStartInfo`.\n\n```powershell\nusing namespace System.Diagnostics\n\n$startTime = [System.DateTime]::Now\n\n# Start PowerShell without a console (DETACHED_PROCESS)\n# Note: Requires .NET 11+\n[Process]::Start(\n [ProcessStartInfo] @{\n FileName = 'pwsh.exe'\n Arguments = '-c \"Start-Sleep 5\"'\n StartDetached = $true\n }\n) | Wait-Process -PassThru | Select-Object *Exit*\n\n\"Ran for $('{0:N1}' -f ([datetime]::Now - $startTime).TotalSeconds) secs.\" | Out-Host\n\n# # As a crosscheck, use the following to provoke a crash that DOES create a WER event.\n# $ps = Start-Process -PassThru conhost.exe (Get-Process -Id $PID).Path; Start-Sleep 2; $ps | Stop-Process\n\n\"Sleeping a little, to give a WER event time to show up\" | Out-Host\n1..5 | ForEach-Object { Write-Host -NoNewline .; Start-Sleep 1 }\nWrite-Host\n\n# Report the resulting WER event, if any.\nGet-WinEvent -FilterHashTable @{\n ProviderName = 'Windows Error Reporting'\n Id = 1001\n Data = 'pwsh.exe' # matches the \u003cData Name=\"P1\"> sub-element of \u003cEventData>\n StartTime = $startTime # events written since this [datetime] instance; supplemnt with `EndTime`, if needed\n} | Format-List\n```\n\nThe offending parts of the source code:\n\n * https://github.com/PowerShell/PowerShell/blob/2725d6aaa6e67219b6c9902adf7b74c52e0371a3/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs#L548-L571\n * https://github.com/PowerShell/PowerShell/blob/2725d6aaa6e67219b6c9902adf7b74c52e0371a3/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs#L105-L111\n\n\n\n### Expected behavior\n\n```console\nRan for 10.0 secs.\n.....\nExitCode HasExited ExitTime\n-------- --------- --------\n 1 True \u003ctimestamp>\n\u003ctabular display of a WER event-log entry with a specific error message>\n```\n\n### Actual behavior\n\n```console\nRan for 0.3 secs.\n.....\nExitCode HasExited ExitTime\n-------- --------- --------\n 0 True \u003ctimestamp>\nGet-WinEvent: foo.ps1:25\nLine |\n 25 | Get-WinEvent -FilterHashTable @{\n | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n | No events were found that match the specified selection criteria.\n```\n\nThat is:\n* the `Start-Sleep` command passed to `-c` never got to execute\n* the exit code was unexpectedly `0`\n* no WER event was logged.\n\n### Error details\n\n```console\n\n```\n\n### Environment data\n\n```powershell\nPowerShell Core v7.7.0-preview.5 on Windows\n```\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2026-11-09T22:28:44Z","url":"https://github.com/PowerShell/PowerShell/issues/28383"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9db43293-eea6-19c3-7065-39975fb716c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A422:11DDE4:34D19D:4891CF:6AFD0F16 |
| html-safe-nonce | ed44c679449caf2efa28563eeaca7d347a7c1f78fa920a0c393963cc95904a0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDIyOjExRERFNDozNEQxOUQ6NDg5MUNGOjZBRkQwRjE2IiwidmlzaXRvcl9pZCI6IjY4MDY3MjY4OTUxNzMwMTUyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 29b344fdb9e0702d338d0f90b7d5a0cfe73d6af7b4015bc5f698bc16f5f7d1a7 |
| hovercard-subject-tag | issue:6295994493 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/28383/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b57b6c260c3eb99a5131b89e2615b979c7fffe055dd69dcfb820387deff84414/PowerShell/PowerShell/issues/28383 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b57b6c260c3eb99a5131b89e2615b979c7fffe055dd69dcfb820387deff84414/PowerShell/PowerShell/issues/28383 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b29de2abb97b6307b16270785efeb58b51a117d5a9b659acf00b77aa00e7043b |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c9e619def6d670dc18a45d3b02cea938c1c7e47 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width