mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 11:06:18 +00:00
Replaced hardcoded paths with values from $env #118
This commit is contained in:
@@ -397,16 +397,13 @@ function ForceRemoveEdge {
|
|||||||
|
|
||||||
Write-Output "Removing leftover files..."
|
Write-Output "Removing leftover files..."
|
||||||
|
|
||||||
$appdata = $([Environment]::GetFolderPath('ApplicationData'))
|
|
||||||
|
|
||||||
$edgePaths = @(
|
$edgePaths = @(
|
||||||
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk",
|
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk",
|
||||||
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
|
||||||
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk",
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk",
|
||||||
|
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk",
|
||||||
"$env:PUBLIC\Desktop\Microsoft Edge.lnk",
|
"$env:PUBLIC\Desktop\Microsoft Edge.lnk",
|
||||||
"$env:USERPROFILE\Desktop\Microsoft Edge.lnk",
|
"$env:USERPROFILE\Desktop\Microsoft Edge.lnk",
|
||||||
"$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk",
|
|
||||||
"$appdata\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
|
|
||||||
"$edgeStub"
|
"$edgeStub"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -475,7 +472,9 @@ function RegImport {
|
|||||||
reg import "$PSScriptRoot\Regfiles\$path"
|
reg import "$PSScriptRoot\Regfiles\$path"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reg load "HKU\Default" "C:\Users\Default\NTUSER.DAT" | Out-Null
|
$defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT')
|
||||||
|
|
||||||
|
reg load "HKU\Default" $defaultUserPath | Out-Null
|
||||||
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
|
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
|
||||||
reg unload "HKU\Default" | Out-Null
|
reg unload "HKU\Default" | Out-Null
|
||||||
}
|
}
|
||||||
@@ -517,7 +516,8 @@ function ReplaceStartMenuForAllUsers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Get path to start menu file for all users
|
# Get path to start menu file for all users
|
||||||
$usersStartMenuPaths = get-childitem -path "C:\Users\*\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
|
# Go through all users and replace the start menu file
|
||||||
ForEach ($startMenuPath in $usersStartMenuPaths) {
|
ForEach ($startMenuPath in $usersStartMenuPaths) {
|
||||||
@@ -525,16 +525,16 @@ function ReplaceStartMenuForAllUsers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Also replace the start menu file for the default user profile
|
# Also replace the start menu file for the default user profile
|
||||||
$defaultProfile = "C:\Users\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
|
# Create folder if it doesn't exist
|
||||||
if (-not(Test-Path $defaultProfile)) {
|
if (-not(Test-Path $defaultStartMenuPath)) {
|
||||||
new-item $defaultProfile -ItemType Directory -Force | Out-Null
|
new-item $defaultStartMenuPath -ItemType Directory -Force | Out-Null
|
||||||
Write-Output "Created LocalState folder for default user"
|
Write-Output "Created LocalState folder for default user profile"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Copy template to default profile
|
# Copy template to default profile
|
||||||
Copy-Item -Path $startMenuTemplate -Destination $defaultProfile -Force
|
Copy-Item -Path $startMenuTemplate -Destination $defaultStartMenuPath -Force
|
||||||
Write-Output "Replaced start menu for the default user profile"
|
Write-Output "Replaced start menu for the default user profile"
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
}
|
}
|
||||||
@@ -544,7 +544,7 @@ function ReplaceStartMenuForAllUsers {
|
|||||||
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
|
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
|
||||||
function ReplaceStartMenu {
|
function ReplaceStartMenu {
|
||||||
param (
|
param (
|
||||||
$startMenuBinFile = "C:\Users\$([Environment]::UserName)\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin",
|
$startMenuBinFile = "$env:LOCALAPPDATA\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin",
|
||||||
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
|
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -698,9 +698,11 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($global:Params.ContainsKey("Sysprep")) {
|
if ($global:Params.ContainsKey("Sysprep")) {
|
||||||
|
$defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT')
|
||||||
|
|
||||||
# Exit script if default user directory or NTUSER.DAT file cannot be found
|
# Exit script if default user directory or NTUSER.DAT file cannot be found
|
||||||
if (-not (Test-Path "C:\Users\Default\NTUSER.DAT")) {
|
if (-not (Test-Path "$defaultUserPath")) {
|
||||||
Write-Host "Error: Unable to start Win11Debloat in Sysprep mode, cannot find default user folder at 'C:\Users\Default\'" -ForegroundColor Red
|
Write-Host "Error: Unable to start Win11Debloat in Sysprep mode, cannot find default user folder at '$defaultUserPath'" -ForegroundColor Red
|
||||||
AwaitKeyToExit
|
AwaitKeyToExit
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
@@ -884,7 +886,7 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP
|
|||||||
Do {
|
Do {
|
||||||
Write-Host "Options:" -ForegroundColor Yellow
|
Write-Host "Options:" -ForegroundColor Yellow
|
||||||
Write-Host " (n) Don't remove any pinned apps from the start menu" -ForegroundColor Yellow
|
Write-Host " (n) Don't remove any pinned apps from the start menu" -ForegroundColor Yellow
|
||||||
Write-Host " (1) Remove all pinned apps from the start menu for this user only ($([Environment]::UserName))" -ForegroundColor Yellow
|
Write-Host " (1) Remove all pinned apps from the start menu for this user only ($env:USERNAME)" -ForegroundColor Yellow
|
||||||
Write-Host " (2) Remove all pinned apps from the start menu for all existing and new users" -ForegroundColor Yellow
|
Write-Host " (2) Remove all pinned apps from the start menu for all existing and new users" -ForegroundColor Yellow
|
||||||
$ClearStartInput = Read-Host "Remove all pinned apps from the start menu? (n/1/2)"
|
$ClearStartInput = Read-Host "Remove all pinned apps from the start menu? (n/1/2)"
|
||||||
}
|
}
|
||||||
@@ -1238,7 +1240,7 @@ else {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
'ClearStart' {
|
'ClearStart' {
|
||||||
Write-Output "> Removing all pinned apps from the start menu for user $([Environment]::UserName)..."
|
Write-Output "> Removing all pinned apps from the start menu for user $env:USERNAME..."
|
||||||
ReplaceStartMenu
|
ReplaceStartMenu
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user