add: cleanup-windows Self-Elevation + .bat-Wrapper
cleanup-windows.ps1:
- Defensive Set-ExecutionPolicy Bypass am Anfang
- Self-Elevation: wenn nicht als Admin gestartet, relauncht das Script
sich selbst als Admin mit -ExecutionPolicy Bypass + Original-Args.
User muss nur einmal UAC bestaetigen, kein extra Befehl mehr noetig.
cleanup-windows.bat:
- Wrapper der powershell.exe mit -ExecutionPolicy Bypass aufruft.
- Funktioniert auch wenn Windows die .ps1 direkt blockt (z.B. unsignierte
Scripts global gesperrt).
- Aufruf: cleanup-windows.bat stefan [-SkipPrune] [-PruneOnly]
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4ea16cfa8f
commit
607a4c9ff8
|
|
@ -0,0 +1,16 @@
|
||||||
|
@echo off
|
||||||
|
REM ════════════════════════════════════════════════════════════════
|
||||||
|
REM ARIA — Cleanup-Wrapper fuer Windows
|
||||||
|
REM ════════════════════════════════════════════════════════════════
|
||||||
|
REM Ruft cleanup-windows.ps1 mit ExecutionPolicy Bypass auf.
|
||||||
|
REM Funktioniert auch wenn Windows .ps1 direkt nicht startet.
|
||||||
|
REM
|
||||||
|
REM Nutzung:
|
||||||
|
REM cleanup-windows.bat stefan
|
||||||
|
REM cleanup-windows.bat stefan -SkipPrune
|
||||||
|
REM
|
||||||
|
REM Doppelklick funktioniert NICHT (braucht Username als Param).
|
||||||
|
REM Per Konsole aufrufen.
|
||||||
|
REM ════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0cleanup-windows.ps1" %*
|
||||||
|
|
@ -34,14 +34,33 @@ param(
|
||||||
[switch]$PruneOnly
|
[switch]$PruneOnly
|
||||||
)
|
)
|
||||||
|
|
||||||
# Admin-Check
|
# Defensive: Process-Scope ExecutionPolicy auf Bypass — verhindert dass
|
||||||
|
# Untersaetze (z.B. Module) blockiert werden. Harmless wenn Parent schon
|
||||||
|
# Bypass aufgerufen hat.
|
||||||
|
try { Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force | Out-Null } catch {}
|
||||||
|
|
||||||
|
# Admin-Check + Self-Elevation
|
||||||
|
# Wenn nicht als Admin gestartet → einmal neu starten als Admin, mit
|
||||||
|
# ExecutionPolicy Bypass + den Original-Argumenten. User muss nur einmal
|
||||||
|
# UAC-Prompt bestaetigen.
|
||||||
$isAdmin = ([Security.Principal.WindowsPrincipal] `
|
$isAdmin = ([Security.Principal.WindowsPrincipal] `
|
||||||
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||||
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||||
if (-not $isAdmin) {
|
if (-not $isAdmin) {
|
||||||
Write-Host "❌ Dieses Script muss als Administrator laufen." -ForegroundColor Red
|
Write-Host "→ Starte neu als Administrator (mit ExecutionPolicy Bypass)..." -ForegroundColor Yellow
|
||||||
Write-Host " Rechtsklick auf PowerShell → 'Als Administrator ausfuehren'" -ForegroundColor Yellow
|
$myPath = $MyInvocation.MyCommand.Path
|
||||||
exit 1
|
$forwardArgs = @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "`"$myPath`"")
|
||||||
|
if ($User) { $forwardArgs += @("-User", $User) }
|
||||||
|
if ($SkipPrune) { $forwardArgs += "-SkipPrune" }
|
||||||
|
if ($PruneOnly) { $forwardArgs += "-PruneOnly" }
|
||||||
|
try {
|
||||||
|
Start-Process powershell.exe -Verb RunAs -ArgumentList $forwardArgs
|
||||||
|
} catch {
|
||||||
|
Write-Host "❌ UAC-Elevation abgebrochen oder fehlgeschlagen." -ForegroundColor Red
|
||||||
|
Write-Host " Rechtsklick auf PowerShell → 'Als Administrator ausfuehren'" -ForegroundColor Yellow
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
$basePath = "C:\Users\$User\AppData\Local"
|
$basePath = "C:\Users\$User\AppData\Local"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue