Raphire / Win11Debloat

A simple, easy to use PowerShell script to remove pre-installed apps from Windows, disable telemetry, remove Bing from Windows search as well as perform various other changes to declutter and improve your Windows experience. This script works for both Windows 10 and Windows 11.
MIT License
14.15k stars 616 forks source link

`Remove-AppxPackage -AllUsers` error on Windows 10 #131

Open GuillaumeHullin opened 1 month ago

GuillaumeHullin commented 1 month ago

Most of the Windows 10 (around 5-6 this week) I tried to run the debloat script failed to uninstall apps with the following error:

Attempting to remove Microsoft.549981C3F5F10...
Remove-AppxPackage : Échec de l’appel de procédure distante.
Échec de l’appel de procédure distante.
Au caractère C:\Users\FTAdmin\AppData\Local\Temp\Win11Debloat\Win11Debloat-master\Win11Debloat.ps1:374 : 98
+ ... ilter Main, Bundle, Resource -AllUsers | Remove-AppxPackage -AllUsers
+                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-AppxPackage], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.Windows.Appx.PackageManager.Comman
   ds.RemoveAppxPackageCommand

I tried Microsoft updates, sfc, reset Microsoft Store, etc... no luck. Anybody?

GuillaumeHullin commented 1 month ago
PS C:\WINDOWS\system32> Get-AppxPackage *Print3D* | Remove-AppxPackage -allusers
Remove-AppxPackage : Échec de l’appel de procédure distante.
Échec de l’appel de procédure distante.
Au caractère Ligne:1 : 29
+ Get-AppxPackage *Print3D* | Remove-AppxPackage -allusers
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-AppxPackage], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.Windows.Appx.PackageManager.Comman
   ds.RemoveAppxPackageCommand
Raphire commented 1 month ago

Heya,

This looks similar to the issue that people encountered a while ago #74. It seems to stem from some kind of bug in Remove-AppxPackage that doesn't exist in Windows 11. I did implement a work-around specifically for Windows 10 that seemed to do the job, but maybe something changed?

I'll see if I can reproduce this issue myself and report back.

GuillaumeHullin commented 1 month ago

There are two more data I can give you: 1- it only happens with systems which are have been used... I tried on a fresh windows 10, it works. 2- I have an other Windows 10 where the Microsoft store package seems to be broken... and the script work fine there.

GuillaumeHullin commented 1 month ago

I found an Windows 10 22H2 with build 19045.4651... and there it works. All the other failing are build 19045.4894. So I'm guessing the problem is the latest upgrade... maybe reinstalling some components would help?

Raphire commented 1 month ago

Thanks again for the additional info, I have some trouble updating my w10 vm's, once I get them up to date I'll test and look for a solution.

Raphire commented 1 month ago

@GuillaumeHullin After updating my VM's I am now on 19045.4957. Uninstalling apps seems to work as expected. Could you see if updating your machines fixes the issue?

GuillaumeHullin commented 1 month ago

I only have access right now to one Win10 but I don't have update available and I'm still at 19045.4894, how did you update?

Raphire commented 1 month ago

I only have access right now to one Win10 but I don't have update available and I'm still at 19045.4894, how did you update?

It seems to be a relatively new release, maybe it's a gradual roll-out. https://support.microsoft.com/en-us/topic/september-24-2024-kb5043131-os-build-19045-4957-preview-2d4a5c54-ac58-4bdb-8685-57d578650e5f

GuillaumeHullin commented 1 month ago

Back on that problem, I got some Windows 10 with the build 19045.4894 and which had the same problem before and it still persists avec the update... any idea?

Raphire commented 1 month ago

Back on that problem, I got some Windows 10 with the build 19045.4894 and which had the same problem before and it still persists avec the update... any idea?

I have been able to reproduce it now on 19045.4894 aswell. It seems to be related to multiple users. Windows 10 seems to have this issue, while Windows 11 doesn't. There seem to be some other reports about this issue on the internet, but no clear reason or solution.

The only workaround that I have found to work is removing the -AllUsers flag from the command. This does however mean the script only uninstalls app for the current user.

GuillaumeHullin commented 1 month ago

But the weird thing is that I have other Windows 10 updated to the same build, and I have no issue running the script. I was thinking maybe comparing some DLLs or other related files that could indicate a difference between the systems but so far I couldn't find anything.

Raphire commented 1 month ago

But the weird thing is that I have other Windows 10 updated to the same build, and I have no issue running the script. I was thinking maybe comparing some DLLs or other related files that could indicate a difference between the systems but so far I couldn't find anything.

Do those machines have multiple users?

GuillaumeHullin commented 1 month ago

All of them. At least 2 admin accounts and one users. None of the admin accounts are linked to a Microsoft account. Some users are. No relations there. Some machines are part of a domain. No relations there either.

Raphire commented 1 month ago

All of them. At least 2 admin accounts and one users. None of the admin accounts are linked to a Microsoft account. Some users are. No relations there. Some machines are part of a domain. No relations there either.

Interesting, thanks for sharing these observations. Are all these machines on Windows 10?

GuillaumeHullin commented 1 month ago

Yes, all Windows 10. On Windows 11 machines, it works fine.

Raphire commented 1 month ago

Yes, all Windows 10. On Windows 11 machines, it works fine.

Just to confirm: Are all Windows 10 machines affected, or do some Windows 10 machines work ok?

From what I can tell so far it seems to be related to Windows 10.

GuillaumeHullin commented 1 month ago

Some Windows 10 machines works okay. I would say 50/50.

Raphire commented 1 month ago

@GuillaumeHullin Very weird indeed. I haven't found any solution for the issue so far, I'll update this thread when I do.

I did find out that app removal only seems bugged when using the -AllUsers switch. So I pushed an update that includes a sort of workaround to ensure the apps are atleast uninstalled for the current user.

GuillaumeHullin commented 1 month ago

Some log from my Windows 10 problems. I tried a few different recently and no issues... until this one.

Attempting to remove Clipchamp.Clipchamp...
Unable to remove *Clipchamp.Clipchamp* for all users
   à System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   à Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand.RemovePackageForAllUsers(String packageFullName, Boolean& encounteredErrors)
   à Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand.ProcessRecord()
   à System.Management.Automation.CommandProcessor.ProcessRecord()
Attempting to remove Microsoft.3DBuilder...
GuillaumeHullin commented 1 month ago

I did find out that app removal only seems bugged when using the -AllUsers switch. So I pushed an update that includes a sort of workaround to ensure the apps are atleast uninstalled for the current user.

Yes, I did see that too. Does your script log when uninstalling without the AllUsers switch?

Raphire commented 1 month ago

I did find out that app removal only seems bugged when using the -AllUsers switch. So I pushed an update that includes a sort of workaround to ensure the apps are atleast uninstalled for the current user.

Yes, I did see that too. Does your script log when uninstalling without the AllUsers switch?

It does log an error if the uninstall fails for the current user. Looking at the output you shared the uninstall did work for the current user.

GuillaumeHullin commented 1 month ago

I did find out that app removal only seems bugged when using the -AllUsers switch. So I pushed an update that includes a sort of workaround to ensure the apps are atleast uninstalled for the current user.

Yes, I did see that too. Does your script log when uninstalling without the AllUsers switch?

It does log an error if the uninstall fails for the current user. Looking at the output you shared the uninstall did work for the current user.

Where do you see that it did work for the current user 😅 ?

Raphire commented 1 month ago

If removal fails for the current user it would show Unable to remove *Clipchamp.Clipchamp* for current user

Admittedly though the current implementation isn't the clearest.

GuillaumeHullin commented 1 month ago

Oh okay. Good to know.