From 2818854d62a3d05da50b055203ac7176bb01b6e9 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 9 Jan 2025 23:08:50 +0100 Subject: [PATCH] Fix: Use regex replace to avoid issue described in #174 (#175) * Fix: Use regex replace to avoid #174 * Fix: Also fix root cause of Raphire#174 in start menu replacement * Fix missing backslash --------- Co-authored-by: Jeffrey <9938813+Raphire@users.noreply.github.com> --- Win11Debloat.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 591e5f4..7224489 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -531,7 +531,7 @@ function RegImport { reg import "$PSScriptRoot\Regfiles\$path" } else { - $defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT') + $defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT' reg load "HKU\Default" $defaultUserPath | Out-Null reg import "$PSScriptRoot\Regfiles\Sysprep\$path" @@ -575,7 +575,7 @@ function ReplaceStartMenuForAllUsers { } # Get path to start menu file for all users - $userPathString = $env:USERPROFILE.Replace($env:USERNAME, "*\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState") + $userPathString = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\*\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState" $usersStartMenuPaths = get-childitem -path $userPathString # Go through all users and replace the start menu file @@ -584,7 +584,7 @@ function ReplaceStartMenuForAllUsers { } # Also replace the start menu file for the default user profile - $defaultStartMenuPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState') + $defaultStartMenuPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState' # Create folder if it doesn't exist if (-not(Test-Path $defaultStartMenuPath)) { @@ -757,7 +757,7 @@ else { } if ($global:Params.ContainsKey("Sysprep")) { - $defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT') + $defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT' # Exit script if default user directory or NTUSER.DAT file cannot be found if (-not (Test-Path "$defaultUserPath")) {