Better exit handling

This commit is contained in:
2025-10-28 15:39:09 +00:00
parent 7a04d81442
commit f482286d8f

View File

@@ -70,6 +70,25 @@ If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
Function Wait-ForKeyOrTimeout {
param (
[int]$Timeout = 10
)
for ($i = $Timeout; $i -ge 0; $i--) {
Write-Host -NoNewline "`rPress any key to close... (Closing in $i seconds) "
if ([System.Console]::KeyAvailable) {
[void][System.Console]::ReadKey($true)
Write-Host "`rKey pressed, exiting countdown... " # Clear line with spaces
return
}
Start-Sleep -Seconds 1
}
Write-Host "`rPress any key to close... (Closing in 0 seconds) " # Clear the last countdown
}
function Run-Trusted([String]$command, $psversion) {
if ($psversion -eq 7) {
@@ -2065,6 +2084,5 @@ if ($ogExecutionPolicy) {
}
Write-Host 'Done! Press Any Key to Exit...' -ForegroundColor Green
$Host.UI.RawUI.ReadKey() *>$null
Wait-ForKeyOrTimeout -Timeout 3
exit