From 8570b02dde14ffad64863f614682c3fc1f87b6c2 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Mon, 23 Oct 2023 16:52:52 +0200 Subject: [PATCH] win: prevent updates from reinstalling apps #260 This commit addresses the issue of unwanted applications being reinstalled during a Windows update. By adding a specific registry entry, this commit ensures that Windows apps, once removed, do not return with subsequent updates. This change ensures more control over the applications present on a Windows system, particularly after an update, enhancing user experience and systeam cleanliness. --- src/application/collections/windows.yaml | 94 ++++++++++++++---------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/src/application/collections/windows.yaml b/src/application/collections/windows.yaml index ca7f5764..083dce7d 100644 --- a/src/application/collections/windows.yaml +++ b/src/application/collections/windows.yaml @@ -9967,47 +9967,63 @@ functions: - name: packageName - name: publisherId call: - function: RunPowerShell - parameters: - code: Get-AppxPackage '{{ $packageName }}' | Remove-AppxPackage - # Package Family Name is: `_`, https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview#publisher-id - revertCode: |- - $packageName='{{ $packageName }}' - $publisherId='{{ $publisherId }}' - Write-Host "Starting the installation process for `"$packageName`"..." - # Attempting installation using the manifest file - Write-Host "Checking if `"$packageName`" is installed on another user profile..." - $package = Get-AppxPackage -AllUsers $packageName - if (!$package) { - Write-Host "`"$packageName`" is not installed on any other user profiles." - } else { - Write-Host "Found package `"$($package.PackageFullName)`"." - $manifestPath = "$($package.InstallLocation)AppxManifest.xml" - if (Test-Path "$manifestPath") { - Write-Host "Manifest file located. Trying to install using the manifest..." - try { - Add-AppxPackage -DisableDevelopmentMode -Register "$manifestPath" -ErrorAction Stop - Write-Host "Successfully installed `"$packageName`" using its manifest file." - exit 0 - } catch { - Write-Warning "Error installing from manifest: $($_.Exception.Message)" - } + - + function: RunPowerShell + parameters: + code: Get-AppxPackage '{{ $packageName }}' | Remove-AppxPackage + # Package Family Name is: `_`, https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview#publisher-id + revertCode: |- + $packageName='{{ $packageName }}' + $publisherId='{{ $publisherId }}' + Write-Host "Starting the installation process for `"$packageName`"..." + # Attempting installation using the manifest file + Write-Host "Checking if `"$packageName`" is installed on another user profile..." + $package = Get-AppxPackage -AllUsers $packageName + if (!$package) { + Write-Host "`"$packageName`" is not installed on any other user profiles." } else { - Write-Host "Manifest file not found for `"$packageName`"." + Write-Host "Found package `"$($package.PackageFullName)`"." + $manifestPath = "$($package.InstallLocation)AppxManifest.xml" + if (Test-Path "$manifestPath") { + Write-Host "Manifest file located. Trying to install using the manifest..." + try { + Add-AppxPackage -DisableDevelopmentMode -Register "$manifestPath" -ErrorAction Stop + Write-Host "Successfully installed `"$packageName`" using its manifest file." + exit 0 + } catch { + Write-Warning "Error installing from manifest: $($_.Exception.Message)" + } + } else { + Write-Host "Manifest file not found for `"$packageName`"." + } } - } - # Attempting installation using the package family name - $packageFamilyName = "$($packageName)_$($publisherId)" - Write-Host "Trying to install `"$packageName`" using its package family name: `"$packageFamilyName`"..." - try { - Add-AppxPackage -RegisterByFamilyName -MainPackage $packageFamilyName -ErrorAction Stop - Write-Host "Successfully installed `"$packageName`" using its package family name." - exit 0 - } catch { - Write-Warning "Error installing using package family name: $($_.Exception.Message)" - } - # If all methods fail - throw "Unable to install `"$packageName`". Please check the provided details and try again." + # Attempting installation using the package family name + $packageFamilyName = "$($packageName)_$($publisherId)" + Write-Host "Trying to install `"$packageName`" using its package family name: `"$packageFamilyName`"..." + try { + Add-AppxPackage -RegisterByFamilyName -MainPackage $packageFamilyName -ErrorAction Stop + Write-Host "Successfully installed `"$packageName`" using its package family name." + exit 0 + } catch { + Write-Warning "Error installing using package family name: $($_.Exception.Message)" + } + # If all methods fail + throw "Unable to install `"$packageName`". Please check the provided details and try again." + - + function: RunInlineCode + # Prevent applications from being reinstalled during a Windows update. + # For more information: + # - https://learn.microsoft.com/en-us/windows/application-management/remove-provisioned-apps-during-update#create-registry-keys-for-deprovisioned-apps + # - Archived: https://archive.ph/04108, https://web.archive.org/web/20231023131048/https://learn.microsoft.com/en-us/windows/application-management/remove-provisioned-apps-during-update#create-registry-keys-for-deprovisioned-apps + # - https://learn.microsoft.com/en-us/mem/configmgr/osd/understand/in-place-upgrade-recommendations#remove-default-apps + # - Archived: https://archive.ph/I7Dwc, https://web.archive.org/web/20231023132613/https://learn.microsoft.com/en-us/mem/configmgr/osd/understand/in-place-upgrade-recommendations#remove-default-apps + parameters: + code: |- + :: Mark the application as deprovisioned to prevent it from reinstalling during Windows updates. + reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned\{{ $packageName }}_{{ $publisherId }}" /f + revertCode: |- + :: Remove the deprovisioned status to allow the application to reinstall during Windows updates. + reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned\{{ $packageName }}_{{ $publisherId }}" /f 2>nul - name: UninstallSystemApp parameters: