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.
This commit is contained in:
@@ -9967,47 +9967,63 @@ functions:
|
|||||||
- name: packageName
|
- name: packageName
|
||||||
- name: publisherId
|
- name: publisherId
|
||||||
call:
|
call:
|
||||||
function: RunPowerShell
|
-
|
||||||
parameters:
|
function: RunPowerShell
|
||||||
code: Get-AppxPackage '{{ $packageName }}' | Remove-AppxPackage
|
parameters:
|
||||||
# Package Family Name is: `<name>_<publisherid>`, https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview#publisher-id
|
code: Get-AppxPackage '{{ $packageName }}' | Remove-AppxPackage
|
||||||
revertCode: |-
|
# Package Family Name is: `<name>_<publisherid>`, https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview#publisher-id
|
||||||
$packageName='{{ $packageName }}'
|
revertCode: |-
|
||||||
$publisherId='{{ $publisherId }}'
|
$packageName='{{ $packageName }}'
|
||||||
Write-Host "Starting the installation process for `"$packageName`"..."
|
$publisherId='{{ $publisherId }}'
|
||||||
# Attempting installation using the manifest file
|
Write-Host "Starting the installation process for `"$packageName`"..."
|
||||||
Write-Host "Checking if `"$packageName`" is installed on another user profile..."
|
# Attempting installation using the manifest file
|
||||||
$package = Get-AppxPackage -AllUsers $packageName
|
Write-Host "Checking if `"$packageName`" is installed on another user profile..."
|
||||||
if (!$package) {
|
$package = Get-AppxPackage -AllUsers $packageName
|
||||||
Write-Host "`"$packageName`" is not installed on any other user profiles."
|
if (!$package) {
|
||||||
} else {
|
Write-Host "`"$packageName`" is not installed on any other user profiles."
|
||||||
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 {
|
} 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
|
||||||
# Attempting installation using the package family name
|
$packageFamilyName = "$($packageName)_$($publisherId)"
|
||||||
$packageFamilyName = "$($packageName)_$($publisherId)"
|
Write-Host "Trying to install `"$packageName`" using its package family name: `"$packageFamilyName`"..."
|
||||||
Write-Host "Trying to install `"$packageName`" using its package family name: `"$packageFamilyName`"..."
|
try {
|
||||||
try {
|
Add-AppxPackage -RegisterByFamilyName -MainPackage $packageFamilyName -ErrorAction Stop
|
||||||
Add-AppxPackage -RegisterByFamilyName -MainPackage $packageFamilyName -ErrorAction Stop
|
Write-Host "Successfully installed `"$packageName`" using its package family name."
|
||||||
Write-Host "Successfully installed `"$packageName`" using its package family name."
|
exit 0
|
||||||
exit 0
|
} catch {
|
||||||
} catch {
|
Write-Warning "Error installing using package family name: $($_.Exception.Message)"
|
||||||
Write-Warning "Error installing using package family name: $($_.Exception.Message)"
|
}
|
||||||
}
|
# If all methods fail
|
||||||
# If all methods fail
|
throw "Unable to install `"$packageName`". Please check the provided details and try again."
|
||||||
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
|
name: UninstallSystemApp
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
Reference in New Issue
Block a user