Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @(set "0=%~f0"^)#) & powershell -nop -c iex([io.file]::ReadAllText($env:0)) & exit /b
- #:: just copy-paste into powershell - it's a standalone hybrid script
- $FORCE_APPX_UNINSTALL = '^_^' ; sp 'HKCU:\Volatile Environment' 'bloat' @'
- $ignore = "UI.Xaml|NET.Native|VCLibs|ShellExperience|StartMenuExperience|immersivecontrolpanel|TextService|DesktopAppInstaller|"+
- "WindowsAppRuntime|UndockedDev|CallingShellApp|PinningConf|PrintDialog|FileExplorer|FilePick|CapturePick|AppResolver|"+
- "NcsiUwpApp|creddialoghost|AccountsControl|LockApp|SecHealth|Windows.Search" # safeguard a few system apps / libs
- $host.ui.RawUI.WindowTitle = 'FORCE APPX UNINSTALL, AveYo 2023.09.20'
- ## enable admin privileges
- $D1=[uri].module.gettype('System.Diagnostics.Process')."GetM`ethods"(42) |where {$_.Name -eq 'SetPrivilege'} #`:no-ev-warn
- 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|foreach {$D1.Invoke($null, @("$_",2))}
- ## shut down explorer, edge & webview clone stuff
- cd $env:systemdrive; taskkill /im explorer.exe /f 2>&1 >''
- $shut = 'explorer','Widgets','widgetservice','msedgewebview2','MicrosoftEdge*','chredge','msedge','edge'
- $shut,'SearchApp','RuntimeBroker','msteams','msfamily','WebViewHost','Clipchamp' |foreach {kill -name $_ -force -ea 0}
- ## removal
- $provisioned = get-appxprovisionedpackage -online; $appxpackage = get-appxpackage -allusers; $custom = @{}
- $provisioned |foreach { $n = $_.InstallLocation; if ($n -notmatch $ignore) {$custom[$_.DisplayName] = $_.InstallLocation} }
- $appxpackage |foreach { $n = $_.InstallLocation; if ($n -notmatch $ignore) {$custom[$_.Name] = $_.InstallLocation} }
- $store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
- $users = @('S-1-5-18'); if (test-path $store) {$users += $((dir $store |where {$_ -like '*S-1-5-21*'}).PSChildName)}
- $picks = $custom.GetEnumerator() | sort -Property Name | out-gridview -passthru -title "Carefully select apps to uninstall"
- foreach ($name in $picks.Name) {
- write-host "*$name*"; if ('' -eq $name) {continue}
- foreach ($appx in $($provisioned |where {$_.InstallLocation -like "*$name*" -or $_.DisplayName -like "*$name*"})) {
- $family = $appxpackage |where {$_.Name -eq $appx.DisplayName}
- write-host -fore Blue $($family.PackageFamilyName)
- ## forced deprovision
- ni "$store\Deprovisioned\$($family.PackageFamilyName)" -force -ea 0 >$null
- ## default deprovision
- dism /online /remove-provisionedappxpackage /packagename:$($appx.PackageName) 2>&1 >$null
- #powershell -nop -c remove-appxprovisionedpackage -packagename "'$($appx.PackageName)'" -online 2>&1 >$null
- }
- foreach ($appx in $($appxpackage |where {$_.InstallLocation -like "*$name*" -or $_.Name -like "*$name*"})) {
- write-host -fore Cyan $($appx.InstallLocation)
- ## remove from inbox
- $inbox = (gp "$store\InboxApplications\*$($appx.Name)*" Path).PSChildName
- foreach ($app in $inbox) {ri "$store\InboxApplications\$app" -recurse -force -ea 0}
- ## forced deprovision
- ni "$store\Deprovisioned\$($appx.PackageFamilyName)" -force -ea 0 >$null
- ## forced unlock - usually works
- foreach ($sid in $users) {ni "$store\EndOfLife\$sid\$($appx.PackageFullName)" -force -ea 0 >$null}
- ## default unlock - usually fails
- dism /online /set-nonremovableapppolicy /packagefamily:$($appx.PackageFamilyName) /nonremovable:0 2>&1 >$null
- ## uninstall silently
- powershell -nop -c remove-appxpackage -package "'$($appx.PackageFullName)'" -AllUsers 2>&1 >$null
- ## optional cleanup experiment - not needed
- #ri "$store\Config\$($appx.PackageFamilyName)" -recurse -force -ea 0
- foreach ($sid in $users) {
- ri "$store\EndOfLife\$sid\$($appx.PackageFullName)" -recurse -force -ea 0
- ri "$store\Deleted\EndOfLife\$sid\$($appx.PackageFullName)" -recurse -force -ea 0
- }
- $inbox = (gp "$store\InboxApplications\*$($appx.Name)*" Path).PSChildName
- foreach ($app in $inbox) {foreach ($sid in $users) {ri "$store\$sid\$app" -recurse -force -ea 0}}
- ## optional delete from disk experiment - not needed, would break restoring from AppxManifest.xml
- #ri "'$($appx.InstallLocation)'" -recurse -force -ea 0
- }
- }
- ## restart explorer
- if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer}
- ## bonus! try to restore system apps if you messed up and uninstalled something needed
- function global:fuckup {
- $all = @(); write-host ' Reinstalling system apps...'; taskkill /im explorer.exe /f 2>&1 >''
- $cfg = @{Register = $true; DisableDevelopmentMode = $true; ForceUpdateFromAnyVersion = $true; ForceApplicationShutdown = $true}
- $all+= dir "$env:SystemRoot\SystemApps\*\AppxManifest.xml" -rec -ea 0 |where {$_ -notlike "*MicrosoftEdge_*"}
- $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -InstallAllResources -ea 0} }
- $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -ea 0} }
- $all | foreach { if (test-path $_) {Add-AppxPackage -Path $_ @cfg -ea 0} }
- if ((get-process -name 'explorer' -ea 0) -eq $null) {start explorer} ; wsreset.exe -i; exit
- }
- ${.} = [char]27; write-host "`n${.}[40;97m UNINSTALLED SOMETHING NEEDED?! ENTER:${.}[95m fuckup ${.}[97m`n"
- ## ask to run script as admin
- '@ -force -ea 0; pushd $env:systemdrive; $env:__COMPAT_LAYER = 'Installer'
- start powershell -args '-noe -nop -c & {iex((gp Registry::HKEY_Users\S-1-5-21*\Volatile* bloat -ea 0)[0].bloat)}' -verb runas
- $PRESS_ENTER_TO_FORCE_APPX_UNINSTALL_ON_YOUR_OWN_RISK = '^_^'
Add Comment
Please, Sign In to add comment