From bfaba1419101d90fd6354e45c4c81180eb1f65a5 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:45:24 +0200 Subject: [PATCH] [MicroWin] Fix Recall "Dependency" Misinformation (#2947) Fixed the misinformation caused by the Recall feature. Thanks @WitherOrNot and @thecatontheceiling for spotting the problem --- .../private/Invoke-WinUtilMicroWin-Helper.ps1 | 26 ++++++++++++++++- functions/public/Invoke-WPFMicrowin.ps1 | 29 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 index b38dc2a2..c1ca7ad0 100644 --- a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 +++ b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 @@ -110,7 +110,6 @@ function Remove-Features() { $_.FeatureName -NotLike "*NFS*" -AND $_.FeatureName -NotLike "*SearchEngine*" -AND $_.FeatureName -NotLike "*RemoteDesktop*" -AND - $_.FeatureName -NotLike "*Recall*" -AND $_.State -ne "Disabled" } @@ -277,6 +276,31 @@ function Remove-ProvisionedPackages() { } } +function Get-LocalizedUsers +{ + <# + .SYNOPSIS + Gets a localized user group representation for ICACLS commands (Port from DISMTools PE Helper) + .PARAMETER admins + Determines whether to get a localized user group representation for the Administrators user group + .OUTPUTS + A string containing the localized user group + .EXAMPLE + Get-LocalizedUsers -admins $true + #> + param ( + [Parameter(Mandatory = $true, Position = 0)] [bool]$admins + ) + if ($admins) + { + return (Get-LocalGroup | Where-Object { $_.SID.Value -like "S-1-5-32-544" }).Name + } + else + { + return (Get-LocalGroup | Where-Object { $_.SID.Value -like "S-1-5-32-545" }).Name + } +} + function Copy-ToUSB([string]$fileToCopy) { foreach ($volume in Get-Volume) { if ($volume -and $volume.FileSystemLabel -ieq "ventoy") { diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index 4b90a5bc..966d6a07 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -162,6 +162,35 @@ public class PowerManagement { Write-Host "Removing Appx Bloat" Remove-ProvisionedPackages + # Detect Windows 11 24H2 and add dependency to FileExp to prevent Explorer look from going back - thanks @WitherOrNot and @thecatontheceiling + if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,26100,1))) -eq $true) + { + try + { + if (Test-Path "$scratchDir\Windows\SystemApps\MicrosoftWindows.Client.FileExp_cw5n1h2txyewy\appxmanifest.xml" -PathType Leaf) + { + # Found the culprit. Do the following: + + # 1. Take ownership of the file, from TrustedInstaller to Administrators + takeown /F "$scratchDir\Windows\SystemApps\MicrosoftWindows.Client.FileExp_cw5n1h2txyewy\appxmanifest.xml" /A + + # 2. Set ACLs so that we can write to it + icacls "$scratchDir\Windows\SystemApps\MicrosoftWindows.Client.FileExp_cw5n1h2txyewy\appxmanifest.xml" /grant "$(Get-LocalizedUsers -admins $true):(M)" | Out-Host + + # 3. Open the file and do the modification + $appxManifest = Get-Content -Path "$scratchDir\Windows\SystemApps\MicrosoftWindows.Client.FileExp_cw5n1h2txyewy\appxmanifest.xml" + $originalLine = $appxManifest[13] + $dependency = "`n " + $appxManifest[13] = "$originalLine$dependency" + Set-Content -Path "$scratchDir\Windows\SystemApps\MicrosoftWindows.Client.FileExp_cw5n1h2txyewy\appxmanifest.xml" -Value $appxManifest -Force -Encoding utf8 + } + } + catch + { + + } + } + Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Windows\System32\LogFiles\WMI\RtBackup" -Directory Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Windows\DiagTrack" -Directory Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Windows\InboxApps" -Directory