diff --git a/install-windows.ps1 b/install-windows.ps1 index 7994190..0bc62f3 100644 --- a/install-windows.ps1 +++ b/install-windows.ps1 @@ -13,11 +13,11 @@ Requires Windows 10/11 with winget (App Installer). No reboot needed. .PARAMETER OwnsWindow - Internal. Set only on the elevated run this script starts for itself, which - gets a console window of its own - so it is allowed to close that window when - it finishes. Without it we assume we are a guest in someone's existing shell - and must not kill it (closing would take their session, and any transcript - they were recording, with it). Not meant to be passed by hand. + Internal. Set only on the elevated run this script starts for itself. That + run has a console of its own, so a fatal error has to pause before the window + disappears with the message on it. In a shell the user already had open the + text stays on screen, and a prompt there is a keystroke nobody asked for. + Not meant to be passed by hand. #> param( [switch]$OwnsWindow @@ -283,10 +283,22 @@ Write-Host " The app opens at http://localhost:8000" -ForegroundColor White Write-Host " The AI starts OFF - click 'Start AI' in the sidebar to turn it on." -ForegroundColor White Write-Host "" Write-Host " Terminal: open a NEW terminal (PowerShell or cmd), then run ncp help" -ForegroundColor White -Write-Host " (PATH is read at process start, so open windows lack it)" -ForegroundColor DarkGray Write-Host " ==========================================================" -ForegroundColor Green Write-Host "" -if ($OwnsWindow) { - Read-Host "Press Enter to close" - exit 0 # -File means the script ending ends powershell.exe, closing the window -} +Write-Host " This window has to close for ncp to work." -ForegroundColor Yellow +Write-Host " A process reads PATH once, when it starts. This shell started before" -ForegroundColor DarkGray +Write-Host " the installer put management\ on PATH, so it will never see ncp no" -ForegroundColor DarkGray +Write-Host " matter what you run here. The next terminal you open will." -ForegroundColor DarkGray +Write-Host "" +Read-Host " Press Enter to close this window (Ctrl+C works too)" + +# Stop-Process on our own PID, not `exit`: `exit` only ends the window when the +# host was started with -File. Run interactively - `& .\install-windows.ps1` from +# a shell already open, which is the common case - it would just return to the +# prompt in a session whose PATH is permanently stale. Killing the host closes +# the window either way, which is the point: the user cannot accidentally keep +# using a shell where ncp will never resolve. +# Caveat: a Start-Transcript in this window never reaches Stop-Transcript. The +# transcript is flushed as it is written, so the content survives without the +# closing footer. +Stop-Process -Id $PID