Fix Start Menu apps not being set correctly for all users when running script for other user (#637)

This commit is contained in:
Jeffrey
2026-06-18 23:02:25 +02:00
committed by GitHub
parent a7a46bb5bf
commit c039b04717
4 changed files with 12 additions and 19 deletions

View File

@@ -92,13 +92,15 @@ function ExecuteParameter {
}
'ClearStart' {
Write-Host "> $($feature.ApplyText) for user $(GetUserName)..."
ReplaceStartMenu
$startMenuBinFile = GetStartMenuBinPathForUser -UserName (GetUserName)
ReplaceStartMenu -startMenuBinFile $startMenuBinFile
Write-Host ""
return
}
'ReplaceStart' {
Write-Host "> $($feature.ApplyText) for user $(GetUserName)..."
ReplaceStartMenu $script:Params.Item("ReplaceStart")
$startMenuBinFile = GetStartMenuBinPathForUser -UserName (GetUserName)
ReplaceStartMenu -startMenuBinFile $startMenuBinFile -startMenuTemplate $script:Params.Item("ReplaceStart")
Write-Host ""
return
}
@@ -107,7 +109,7 @@ function ExecuteParameter {
return
}
'ReplaceStartAllUsers' {
ReplaceStartMenuForAllUsers $script:Params.Item("ReplaceStartAllUsers")
ReplaceStartMenuForAllUsers -startMenuTemplate $script:Params.Item("ReplaceStartAllUsers")
return
}
'DisableStoreSearchSuggestions' {

View File

@@ -2,7 +2,7 @@
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
function ReplaceStartMenuForAllUsers {
param (
$startMenuTemplate = "$script:AssetsPath\Start\start2.bin"
[string]$startMenuTemplate = "$script:AssetsPath\Start\start2.bin"
)
Write-Host "> Removing all pinned apps from the start menu for all users..."
@@ -20,7 +20,7 @@ function ReplaceStartMenuForAllUsers {
# Go through all users and replace the start menu file
ForEach ($startMenuPath in $usersStartMenuPaths) {
ReplaceStartMenu $startMenuTemplate "$($startMenuPath.Fullname)\start2.bin"
ReplaceStartMenu -startMenuBinFile "$($startMenuPath.Fullname)\start2.bin" -startMenuTemplate $startMenuTemplate
}
# Also replace the start menu file for the default user profile
@@ -33,7 +33,7 @@ function ReplaceStartMenuForAllUsers {
}
# Copy template to default profile
Copy-Item -Path $startMenuTemplate -Destination $defaultStartMenuPath -Force
ReplaceStartMenu -startMenuBinFile "$($defaultStartMenuPath)\start2.bin" -startMenuTemplate $startMenuTemplate
Write-Host "Replaced start menu for the default user profile"
Write-Host ""
}
@@ -43,22 +43,18 @@ function ReplaceStartMenuForAllUsers {
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
function ReplaceStartMenu {
param (
$startMenuTemplate = "$script:AssetsPath\Start\start2.bin",
$startMenuBinFile = "$env:LOCALAPPDATA\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin"
[Parameter(Mandatory)]
[string]$startMenuBinFile,
[string]$startMenuTemplate = "$script:AssetsPath\Start\start2.bin"
)
# Change path to correct user if a user was specified
if ($script:Params.ContainsKey("User")) {
$startMenuBinFile = GetStartMenuBinPathForUser -UserName (GetUserName)
}
# Check if template bin file exists
if (-not (Test-Path $startMenuTemplate)) {
Write-Host "Error: Unable to replace start menu, template file not found" -ForegroundColor Red
return
}
if ([IO.Path]::GetExtension($startMenuTemplate) -ne ".bin" ) {
if ([IO.Path]::GetExtension($startMenuTemplate) -ne ".bin") {
Write-Host "Error: Unable to replace start menu, template file is not a valid .bin file" -ForegroundColor Red
return
}
@@ -113,7 +109,6 @@ function RestoreStartMenuFromBackup {
param(
[Parameter(Mandatory)]
[string]$StartMenuBinFile,
[Parameter(Mandatory = $false)]
[string]$BackupFilePath
)
@@ -157,7 +152,6 @@ function RestoreStartMenuFromBackup {
function RestoreStartMenu {
param(
[Parameter(Mandatory = $false)]
[string]$BackupFilePath
)
@@ -171,7 +165,6 @@ function RestoreStartMenu {
function RestoreStartMenuForAllUsers {
param(
[Parameter(Mandatory = $false)]
[string]$BackupFilePath
)

View File

@@ -1,6 +1,5 @@
function Show-RestoreBackupDialog {
param(
[Parameter(Mandatory = $false)]
[System.Windows.Window]$Owner = $null
)

View File

@@ -1,6 +1,5 @@
function Show-RestoreBackupWindow {
param(
[Parameter(Mandatory = $false)]
[System.Windows.Window]$Owner = $null
)