diff --git a/AGENTS.md b/AGENTS.md index c249694..80769ff 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,7 +29,8 @@ always work. Proxmox tools: `therepos/proxmox`; MCP servers: `therepos/mcp`; Cla - `elevate`: `if (-not (Test-Admin)) { Start-Elevated $ScriptUrl; return }`, only when admin is needed; `-NoExit` for one-shot scripts whose output must stay. Re-runs the bootstrap, or the local copy when started from a shortcut, in an admin Windows Terminal window (Windows ignores the default-terminal - setting for admin windows); classic console when Terminal is missing. + setting for admin windows); classic console when Terminal is missing. Once it opens, the original + window closes (only one window at a time); if the admin prompt is refused, it stays with `Cancelled.` - `layout`: `Set-WindowRight` at top level before the first screen (after the elevate check, never in a hidden or scheduled run) puts the window on the right half of its screen. - `shortcut`: every script with a menu offers Settings > `Shortcut '' [on/off]`. It saves a local diff --git a/apps/agentprofiler.ps1 b/apps/agentprofiler.ps1 index 0e9bf41..542d31a 100644 --- a/apps/agentprofiler.ps1 +++ b/apps/agentprofiler.ps1 @@ -38,8 +38,16 @@ function Start-Elevated([string]$ScriptUrl, [switch]$NoExit) { } } } - if (-not $opened) { Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs } - Write-Host " Continue in the new (elevated) window. You can close this one." -ForegroundColor Gray + if (-not $opened) { + try { + Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs -ErrorAction Stop + } catch { + Write-Host " Cancelled." -ForegroundColor Yellow + return + } + } + # Only the admin window stays open + [Environment]::Exit(0) } # <<< elevate $IsAdmin = Test-Admin diff --git a/apps/appupdate.ps1 b/apps/appupdate.ps1 index e34fff9..1c15bee 100644 --- a/apps/appupdate.ps1 +++ b/apps/appupdate.ps1 @@ -65,8 +65,16 @@ function Start-Elevated([string]$ScriptUrl, [switch]$NoExit) { } } } - if (-not $opened) { Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs } - Write-Host " Continue in the new (elevated) window. You can close this one." -ForegroundColor Gray + if (-not $opened) { + try { + Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs -ErrorAction Stop + } catch { + Write-Host " Cancelled." -ForegroundColor Yellow + return + } + } + # Only the admin window stays open + [Environment]::Exit(0) } # <<< elevate $IsAdmin = Test-Admin diff --git a/apps/hibernate.ps1 b/apps/hibernate.ps1 index 042e2bb..0c3b234 100644 --- a/apps/hibernate.ps1 +++ b/apps/hibernate.ps1 @@ -33,8 +33,16 @@ function Start-Elevated([string]$ScriptUrl, [switch]$NoExit) { } } } - if (-not $opened) { Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs } - Write-Host " Continue in the new (elevated) window. You can close this one." -ForegroundColor Gray + if (-not $opened) { + try { + Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs -ErrorAction Stop + } catch { + Write-Host " Cancelled." -ForegroundColor Yellow + return + } + } + # Only the admin window stays open + [Environment]::Exit(0) } # <<< elevate $IsAdmin = Test-Admin diff --git a/apps/systeminfo.ps1 b/apps/systeminfo.ps1 index 0b035da..99bf38d 100644 --- a/apps/systeminfo.ps1 +++ b/apps/systeminfo.ps1 @@ -45,8 +45,16 @@ function Start-Elevated([string]$ScriptUrl, [switch]$NoExit) { } } } - if (-not $opened) { Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs } - Write-Host " Continue in the new (elevated) window. You can close this one." -ForegroundColor Gray + if (-not $opened) { + try { + Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs -ErrorAction Stop + } catch { + Write-Host " Cancelled." -ForegroundColor Yellow + return + } + } + # Only the admin window stays open + [Environment]::Exit(0) } # <<< elevate $IsAdmin = Test-Admin diff --git a/scripts/sync-blocks.sh b/scripts/sync-blocks.sh index 0c6a2a3..c44edef 100755 --- a/scripts/sync-blocks.sh +++ b/scripts/sync-blocks.sh @@ -66,7 +66,7 @@ BLOCK # elevate: re-run this script as admin, in Windows Terminal when installed (Windows ignores # the default-terminal setting for admin windows). From GitHub it re-runs the bootstrap, from a -# file (shortcut) that file. -NoExit keeps the admin window open after a one-shot script. +# file (shortcut) that file, then closes this window. -NoExit keeps the admin window open after a one-shot script. # shellcheck disable=SC2034 # read via ${!var} below BLOCK_elevate=$(cat <<'BLOCK' function Test-Admin { @@ -97,8 +97,16 @@ function Start-Elevated([string]$ScriptUrl, [switch]$NoExit) { } } } - if (-not $opened) { Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs } - Write-Host " Continue in the new (elevated) window. You can close this one." -ForegroundColor Gray + if (-not $opened) { + try { + Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $psArgs -ErrorAction Stop + } catch { + Write-Host " Cancelled." -ForegroundColor Yellow + return + } + } + # Only the admin window stays open + [Environment]::Exit(0) } BLOCK )