From cd5ba8ea8b0c5e27f5f435cfa00ee3cc47cb6492 Mon Sep 17 00:00:00 2001 From: Jeffrey <9938813+Raphire@users.noreply.github.com> Date: Sat, 4 Jul 2026 17:33:42 +0200 Subject: [PATCH] Also escape unbound arguments, just in case --- Win11Debloat.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 751d2de..1917680 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -111,11 +111,7 @@ if (-not $isAdmin) { $choice = Read-Host "Restart as Administrator? (y/n)" if ($choice -match '^[Yy]$') { - # Win32-safe argument quoting for Start-Process -ArgumentList. Windows PowerShell 5.1 joins the - # array with spaces and does not quote, so each value is re-parsed by CommandLineToArgvW on the - # elevated side. Double any backslashes that precede a quote or the closing quote, escape embedded - # quotes, then wrap -- otherwise a value containing '"' or ending in '\' (e.g. a directory path) - # corrupts the relaunch command line. + # Win32-safe escaping for arguments to pass to elevated process function Format-ElevatedArg([string]$Value) { $escaped = $Value -replace '(\\*)"', '$1$1\"' $escaped = $escaped -replace '(\\+)$', '$1$1' @@ -139,7 +135,9 @@ if (-not $isAdmin) { } if ($MyInvocation.UnboundArguments.Count -gt 0) { - $elevatedArgs += $MyInvocation.UnboundArguments + foreach ($unboundArg in $MyInvocation.UnboundArguments) { + $elevatedArgs += (Format-ElevatedArg "$unboundArg") + } } Start-Process powershell -ArgumentList $elevatedArgs -Verb RunAs