mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 02:56:17 +00:00
Fix issue with clearing/replacing start for default user when directory doesn't exist yet #314
This commit is contained in:
@@ -575,21 +575,26 @@ function CheckModernStandbySupport {
|
|||||||
function GetUserDirectory {
|
function GetUserDirectory {
|
||||||
param (
|
param (
|
||||||
$userName,
|
$userName,
|
||||||
$fileName = ""
|
$fileName = "",
|
||||||
|
$exitIfPathNotFound = $true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$userDirectoryExists = Test-Path "$env:SystemDrive\Users\$userName"
|
||||||
$userPath = "$env:SystemDrive\Users\$userName\$fileName"
|
$userPath = "$env:SystemDrive\Users\$userName\$fileName"
|
||||||
|
|
||||||
if (-not (Test-Path $userPath)) {
|
if ((Test-Path $userPath) -or ($userDirectoryExists -and (-not $exitIfPathNotFound))) {
|
||||||
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName\$fileName"
|
return $userPath
|
||||||
|
}
|
||||||
|
|
||||||
|
$userDirectoryExists = Test-Path $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName"
|
||||||
|
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$userName\$fileName"
|
||||||
|
|
||||||
|
if ((Test-Path $userPath) -or ($userDirectoryExists -and (-not $exitIfPathNotFound))) {
|
||||||
|
return $userPath
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path $userPath)) {
|
|
||||||
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
|
||||||
}
|
|
||||||
|
|
||||||
return $userPath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -682,7 +687,7 @@ function ReplaceStartMenuForAllUsers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Also replace the start menu file for the default user profile
|
# Also replace the start menu file for the default user profile
|
||||||
$defaultStartMenuPath = GetUserDirectory -userName "Default" -fileName "AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState"
|
$defaultStartMenuPath = GetUserDirectory -userName "Default" -fileName "AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState" -exitIfPathNotFound $false
|
||||||
|
|
||||||
# Create folder if it doesn't exist
|
# Create folder if it doesn't exist
|
||||||
if (-not (Test-Path $defaultStartMenuPath)) {
|
if (-not (Test-Path $defaultStartMenuPath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user