Thanks for the testing @garlin
I've updated the script and will attach it here.
However for me, it seems very hit and miss if it works now on my daily use PC! On my test VM it's great and works every time.
I've updated the script and will attach it here.
However for me, it seems very hit and miss if it works now on my daily use PC! On my test VM it's great and works every time.
Powershell:
Param( [Parameter(ValueFromPipelineByPropertyName)]$RemoveStartMenuItems = $True,
[Parameter(ValueFromPipelineByPropertyName)]$RestartExplorer = $True )
Function Restart-Process
{
Param( [Parameter(ValueFromPipelineByPropertyName)]$Name,
[Parameter(ValueFromPipelineByPropertyName)]$Wait,
[Parameter(ValueFromPipelineByPropertyName)]$Timeout,
[Parameter(ValueFromPipelineByPropertyName)]$Kill,
[Parameter(ValueFromPipelineByPropertyName)]$Start )
Process
{
If ( $Kill )
{
$szSystem32Path = [Environment]::GetFolderPath("System")
$szTaskKillBinary = "$szSystem32Path\taskkill.exe"
Write-Host -ForegroundColor White "Killing the process '$Name'..."
# Note, stopping Explorer like this will cause it to not automatically restart
Start-Process -WindowStyle Hidden -Wait -FilePath $szTaskKillBinary -ArgumentList "/F /IM $Name"
}
Else
{
Write-Host -ForegroundColor White "Stopping the process '$Name'..."
Stop-Process -Name $Name -Force # Note, stopping Explorer like this will cause it to automatically restart
Write-Host -ForegroundColor White "Waiting for the process '$Name' to stop..."
Wait-Process -Name $Name -Timeout $Timeout
}
If ( $Start )
{
Write-Host -ForegroundColor White "Starting the process '$Name'..."
If ( $Name -Eq "explorer.exe" )
{
Start-Process -WindowStyle Hidden -FilePath "cmd" -ArgumentList "/c start /wait $Name"
}
Else
{
# Wait doesn't work on explorer
Start-Process -WindowStyle Hidden -Wait -FilePath $Name
}
}
$szNameWithoutExtension = [io.path]::GetFilenameWithoutExtension( $Name )
Write-Host -ForegroundColor White "Waiting for the process '$szNameWithoutExtension' to start..."
$iCount = 0
While ( ((Get-Process -Name $szNameWithoutExtension -ErrorAction SilentlyContinue).Count -Eq 0) -And ($iCount -lt $Timeout) )
{
Start-Sleep -Seconds 1
$iCount++
}
Write-Host -ForegroundColor White "Waiting $Wait seconds..."
Start-Sleep -Seconds $Wait
}
}
Function Remove_NonRemovablePackage
{
Param( [Parameter(ValueFromPipelineByPropertyName)]$Name )
Process
{
$bRet = $False
Write-Host -ForegroundColor White "Getting details for package '$Name'..."
$objAppx = Get-AppxPackage -AllUsers -Name $Name
If ( $Null -Ne $objAppx )
{
If ( $objAppx.Count -Gt 1 ) { $objAppx = $objAppx[0] }
$szStoreRegKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore"
$aszUserSIDs = @( "S-1-5-18" )
If ( Test-Path -Path $szStoreRegKey )
{
$aszUserSIDs += $((Get-ChildItem -Path $szStoreRegKey -ErrorAction SilentlyContinue | Where {$_ -Like '*S-1-5-21*'}).PSChildName)
}
Write-Host -ForegroundColor White "Setting package '$($objAppx.PackageFamilyName)' to Deprovisioned..."
$objDeprovisionedRegKey = New-Item -Force -Path "$szStoreRegKey\Deprovisioned\$objAppx.PackageFamilyName"
ForEach ( $szUserSID in $aszUserSIDs )
{
Write-Host -ForegroundColor White "Setting package '$($objAppx.PackageFullName)' to End-of-life for user SID '$szUserSID'..."
$objEOLRegKey = New-Item -Force -Path "$szStoreRegKey\EndOfLife\$szUserSID\$($objAppx.PackageFullName)"
}
Write-Host -ForegroundColor White "Removing package '$($objAppx.PackageFullName)' for all users..."
$objRemovedPackage = Remove-AppxPackage -AllUsers -Package $($objAppx.PackageFullName)
$bRet = $True
Write-Host -ForegroundColor White "Waing a second..."
Start-Sleep -Seconds 1
}
Else
{
Write-Host -ForegroundColor Red "ERROR: No package found called '$Name'."
}
Return $bRet
}
}
Function Remove_StartMenuCBSItems
{
Param( [Parameter(ValueFromPipelineByPropertyName)]$RestartExplorer )
Process
{
$szCBSName = "MicrosoftWindows.Client.CBS"
$szCBSAppName = "$($szCBSName)_cw5n1h2txyewy"
$szWindowsPath = [Environment]::GetFolderPath( "Windows" )
$szCBSXMLPath = "$szWindowsPath\SystemApps\$($szCBSAppName)\appxmanifest.xml"
Write-Host -ForegroundColor White "Creating a backup of the Appx manifest file for '$szCBSAppName'..."
$szCurrentTime = (Get-Date).ToString( "yyyy-MM-dd_HH-mm-ss" )
$szBackFilePath = "$($szCBSXMLPath)_$($szCurrentTime).xml"
Copy-Item -Force -Path $szCBSXMLPath -Destination "$($szCBSXMLPath)_$($szCurrentTime).xml"
Write-Host -ForegroundColor White "Reading the Appx manifest file for '$szCBSAppName'..."
$xmlCBS = [XML]( Get-Content $szCBSXMLPath )
$xmlCBSNode = $xmlCBS.Package.Applications.Application | Where-Object { $_.Id -Eq "WebExperienceHost" }
If ( $xmlCBSNode.VisualElements )
{
Write-Host -ForegroundColor White "Hiding the Start menu item 'Get Started'..."
$xmlCBSNode.VisualElements.SetAttribute( "AppListEntry", "none" )
}
$xmlCBSNode = $xmlCBS.Package.Applications.Application | Where-Object { $_.Id -Eq "WindowsBackup" }
If ( $xmlCBSNode.VisualElements )
{
Write-Host -ForegroundColor White "Hiding the Start menu item 'Windows Back up'..."
$xmlCBSNode.VisualElements.SetAttribute( "AppListEntry", "none" )
}
$xmlCBSNode = $xmlCBS.Package.Applications.Application | Where-Object { $_.Id -Eq "CrossDeviceResumeApp" }
If ( $xmlCBSNode.VisualElements )
{
Write-Host -ForegroundColor White "Hiding the Start menu item 'Continue from Phone'..."
$xmlCBSNode.VisualElements.SetAttribute( "AppListEntry", "none" )
}
$szUser = "Administrators"
$aclOrig = Get-Acl $szCBSXMLPath
$aclPath = Get-Acl $szCBSXMLPath
Write-Host -ForegroundColor White "Setting '$szUser' to have full control of '$szCBSXMLPath'..."
$arPath = New-Object System.Security.AccessControl.FileSystemAccessRule( $szUser, "FullControl", $([System.Security.AccessControl.InheritanceFlags]::None), "None", "Allow" )
$aclPath.SetAccessRule( $arPath )
Set-Acl $szCBSXMLPath $aclPath
Write-Host -ForegroundColor White "Saving the updated Appx manifest file for '$szCBSAppName'..."
$objUTF8WithoutBOM = New-Object System.Text.UTF8Encoding( $False )
$objUTF8WithoutBOMSW = New-Object System.IO.StreamWriter( $szCBSXMLPath, $False, $objUTF8WithoutBOM )
$xmlCBS.Save( $objUTF8WithoutBOMSW )
$objUTF8WithoutBOMSW.Close()
$bRemoved = Remove_NonRemovablePackage -Name $szCBSName
Write-Host -ForegroundColor White "Installing package '$szCBSAppName'..."
Add-AppxPackage -ForceApplicationShutdown -DisableDevelopmentMode -Register $szCBSXMLPath
Write-Host -ForegroundColor White "Waing a second..."
Start-Sleep -Seconds 1
If ( $RestartExplorer ) { Restart-Process -Name "explorer.exe" -Wait 0 -Timeout 5 -Kill:$True -Start:$True }
Write-Host -ForegroundColor White "Restoring the original AppX manifest file..."
Move-Item -Force -Path $szBackFilePath -Destination $szCBSXMLPath
Write-Host -ForegroundColor White "Resetting permissions on '$szCBSXMLPath'..."
Set-Acl $szCBSXMLPath $aclOrig
}
}
Function Restore_StartMenuCBSItems
{
Param( [Parameter(ValueFromPipelineByPropertyName)]$RestartExplorer )
Process
{
$szCBSName = "MicrosoftWindows.Client.CBS"
$szCBSAppName = "$($szCBSName)_cw5n1h2txyewy"
$szWindowsPath = [Environment]::GetFolderPath( "Windows" )
$szCBSXMLPath = "$szWindowsPath\SystemApps\$($szCBSAppName)\appxmanifest.xml"
$bRemoved = Remove_NonRemovablePackage -Name $szCBSName
Write-Host -ForegroundColor White "Installing package '$szCBSAppName'..."
Add-AppxPackage -ForceApplicationShutdown -DisableDevelopmentMode -Register $szCBSXMLPath
If ( $RestartExplorer ) { Restart-Process -Name "explorer.exe" -Wait 0 -Timeout 5 -Kill:$True -Start:$True }
}
}
If ( $RemoveStartMenuItems )
{
Remove_StartMenuCBSItems -RestartExplorer:$RestartExplorer
}
Else
{
Restore_StartMenuCBSItems -RestartExplorer:$RestartExplorer
}
Attachments
My Computer
System One
-
- OS
- Windows 11