aveyo

FORCE_APPX_UNINSTALL

Dec 5th, 2020 (edited)
3,352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.44 KB | None | 0 0
  1. @(set "0=%~f0"^)#) & powershell -nop -c iex([io.file]::ReadAllText($env:0)) & exit /b
  2. #:: just copy-paste into powershell - it's a standalone hybrid script
  3.  
  4. $FORCE_APPX_UNINSTALL = '^_^' ; sp 'HKCU:\Volatile Environment' 'bloat' @'
  5.  
  6. $ignore = "UI.Xaml|NET.Native|VCLibs|ShellExperience|StartMenuExperience|immersivecontrolpanel|TextService|DesktopAppInstaller|"+
  7.           "WindowsAppRuntime|UndockedDev|CallingShellApp|PinningConf|PrintDialog|FileExplorer|FilePick|CapturePick|AppResolver|"+
  8.           "NcsiUwpApp|creddialoghost|AccountsControl|LockApp|SecHealth|Windows.Search" # safeguard a few system apps / libs
  9.  
  10. $host.ui.RawUI.WindowTitle = 'FORCE APPX UNINSTALL, AveYo 2023.09.20'
  11. ## enable admin privileges
  12. $D1=[uri].module.gettype('System.Diagnostics.Process')."GetM`ethods"(42) |where {$_.Name -eq 'SetPrivilege'} #`:no-ev-warn
  13. 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|foreach {$D1.Invoke($null, @("$_",2))}
  14. ## shut down explorer, edge & webview clone stuff
  15. cd $env:systemdrive; taskkill /im explorer.exe /f 2>&1 >''
  16. $shut = 'explorer','Widgets','widgetservice','msedgewebview2','MicrosoftEdge*','chredge','msedge','edge'
  17. $shut,'SearchApp','RuntimeBroker','msteams','msfamily','WebViewHost','Clipchamp' |foreach {kill -name $_ -force -ea 0}
  18.  
  19. ## removal
  20. $provisioned = get-appxprovisionedpackage -online; $appxpackage = get-appxpackage -allusers; $custom = @{}
  21. $provisioned |foreach { $n = $_.InstallLocation; if ($n -notmatch $ignore) {$custom[$_.DisplayName] = $_.InstallLocation} }
  22. $appxpackage |foreach { $n = $_.InstallLocation; if ($n -notmatch $ignore) {$custom[$_.Name] = $_.InstallLocation} }
  23. $store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
  24. $users = @('S-1-5-18'); if (test-path $store) {$users += $((dir $store |where {$_ -like '*S-1-5-21*'}).PSChildName)}
  25. $picks = $custom.GetEnumerator() | sort -Property Name | out-gridview -passthru -title "Carefully select apps to uninstall"
  26. foreach ($name in $picks.Name) {
  27.   write-host "*$name*"; if ('' -eq $name) {continue}
  28.   foreach ($appx in $($provisioned |where {$_.InstallLocation -like "*$name*" -or $_.DisplayName -like "*$name*"})) {
  29.     $family = $appxpackage |where {$_.Name -eq $appx.DisplayName}
  30.     write-host -fore Blue $($family.PackageFamilyName)
  31.     ## forced deprovision
  32.     ni "$store\Deprovisioned\$($family.PackageFamilyName)" -force -ea 0 >$null
  33.     ## default deprovision
  34.     dism /online /remove-provisionedappxpackage /packagename:$($appx.PackageName) 2>&1 >$null
  35.     #powershell -nop -c remove-appxprovisionedpackage -packagename "'$($appx.PackageName)'" -online 2>&1 >$null
  36.   }
  37.   foreach ($appx in $($appxpackage |where {$_.InstallLocation -like "*$name*" -or $_.Name -like "*$name*"})) {
  38.     write-host -fore Cyan $($appx.InstallLocation)
  39.     ## remove from inbox
  40.     $inbox = (gp "$store\InboxApplications\*$($appx.Name)*" Path).PSChildName
  41.     foreach ($app in $inbox) {ri "$store\InboxApplications\$app" -recurse -force -ea 0}
  42.     ## forced deprovision
  43.     ni "$store\Deprovisioned\$($appx.PackageFamilyName)" -force -ea 0 >$null
  44.     ## forced unlock - usually works
  45.     foreach ($sid in $users) {ni "$store\EndOfLife\$sid\$($appx.PackageFullName)" -force -ea 0 >$null}
  46.     ## default unlock - usually fails
  47.     dism /online /set-nonremovableapppolicy /packagefamily:$($appx.PackageFamilyName) /nonremovable:0 2>&1 >$null
  48.     ## uninstall silently
  49.     powershell -nop -c remove-appxpackage -package "'$($appx.PackageFullName)'" -AllUsers 2>&1 >$null
  50.     ## optional cleanup experiment - not needed
  51.     #ri "$store\Config\$($appx.PackageFamilyName)" -recurse -force -ea 0
  52.     foreach ($sid in $users) {
  53.       ri "$store\EndOfLife\$sid\$($appx.PackageFullName)" -recurse -force -ea 0
  54.       ri "$store\Deleted\EndOfLife\$sid\$($appx.PackageFullName)" -recurse -force -ea 0
  55.     }
  56.     $inbox = (gp "$store\InboxApplications\*$($appx.Name)*" Path).PSChildName
  57.     foreach ($app in $inbox) {foreach ($sid in $users) {ri "$store\$sid\$app" -recurse -force -ea 0}}
  58.     ## optional delete from disk experiment - not needed, would break restoring from AppxManifest.xml
  59.     #ri "'$($appx.InstallLocation)'" -recurse -force -ea 0
  60.   }
  61. }
  62.  
  63. ## restart explorer
  64. if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer}
  65.  
  66. ## bonus! try to restore system apps if you messed up and uninstalled something needed
  67. function global:fuckup {
  68.   $all = @(); write-host ' Reinstalling system apps...'; taskkill /im explorer.exe /f 2>&1 >''
  69.   $cfg = @{Register = $true; DisableDevelopmentMode = $true; ForceUpdateFromAnyVersion = $true; ForceApplicationShutdown = $true}
  70.   $all+= dir "$env:SystemRoot\SystemApps\*\AppxManifest.xml" -rec -ea 0 |where {$_ -notlike "*MicrosoftEdge_*"}
  71.   $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -InstallAllResources -ea 0} }
  72.   $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -ea 0} }
  73.   $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -ea 0} }
  74.   if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer} ; wsreset.exe -i; exit
  75. }
  76. ${.} = [char]27; write-host "`n${.}[40;97m UNINSTALLED SOMETHING NEEDED?! ENTER:${.}[95m fuckup ${.}[97m`n"
  77.  
  78. ## ask to run script as admin
  79. '@ -force -ea 0; pushd $env:systemdrive; $env:__COMPAT_LAYER = 'Installer'
  80. start powershell -args '-noe -nop -c & {iex((gp Registry::HKEY_Users\S-1-5-21*\Volatile* bloat -ea 0)[0].bloat)}' -verb runas
  81.  
  82. $PRESS_ENTER_TO_FORCE_APPX_UNINSTALL_ON_YOUR_OWN_RISK = '^_^'
  83.  
Add Comment
Please, Sign In to add comment