mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 02:56:17 +00:00
Fix issue where clearing/replacing the start menu pinned apps would fail and crash under certain circumstances, part 2
This commit is contained in:
@@ -582,6 +582,7 @@ function GetUserDirectory {
|
|||||||
$exitIfPathNotFound = $true
|
$exitIfPathNotFound = $true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
$userDirectoryExists = Test-Path "$env:SystemDrive\Users\$userName"
|
$userDirectoryExists = Test-Path "$env:SystemDrive\Users\$userName"
|
||||||
$userPath = "$env:SystemDrive\Users\$userName\$fileName"
|
$userPath = "$env:SystemDrive\Users\$userName\$fileName"
|
||||||
|
|
||||||
@@ -589,12 +590,16 @@ function GetUserDirectory {
|
|||||||
return $userPath
|
return $userPath
|
||||||
}
|
}
|
||||||
|
|
||||||
$userDirectoryExists = Test-Path $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName"
|
$userDirectoryExists = Test-Path ($env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName")
|
||||||
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName\$fileName"
|
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName\$fileName"
|
||||||
|
|
||||||
if ((Test-Path $userPath) -or ($userDirectoryExists -and (-not $exitIfPathNotFound))) {
|
if ((Test-Path $userPath) -or ($userDirectoryExists -and (-not $exitIfPathNotFound))) {
|
||||||
return $userPath
|
return $userPath
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host "Error: Something went wrong when trying to find the user directory path for user $userName. Please ensure the user exists on this system." -ForegroundColor Red
|
||||||
|
AwaitKeyToExit
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Error: Unable to find user directory path for user $userName" -ForegroundColor Red
|
Write-Host "Error: Unable to find user directory path for user $userName" -ForegroundColor Red
|
||||||
AwaitKeyToExit
|
AwaitKeyToExit
|
||||||
@@ -738,6 +743,7 @@ function ReplaceStartMenu {
|
|||||||
Move-Item -Path $startMenuBinFile -Destination $backupBinFile -Force
|
Move-Item -Path $startMenuBinFile -Destination $backupBinFile -Force
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Warning: Unable to find original start2.bin file for user $userName. No backup was created for this user!" -ForegroundColor Yellow
|
Write-Host "Warning: Unable to find original start2.bin file for user $userName. No backup was created for this user!" -ForegroundColor Yellow
|
||||||
|
New-Item -ItemType File -Path $startMenuBinFile -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
# Copy template file
|
# Copy template file
|
||||||
|
|||||||
Reference in New Issue
Block a user