Unable to uninstall Universal Apps through PowerShell

The post Clean removal of system apps (bypass error 0x80073CFA) contains this PowerShell script :

function Enable-Privilege {  
  param($Privilege)
  $Definition = @'
using System;  
using System.Runtime.InteropServices;  
public class AdjPriv {  
  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr rele);
  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
  [DllImport("advapi32.dll", SetLastError = true)]
  internal static extern bool LookupPrivilegeValue(string host, string name,
    ref long pluid);
  [StructLayout(LayoutKind.Sequential, Pack = 1)]
  internal struct TokPriv1Luid {
    public int Count;
    public long Luid;
    public int Attr;
  }
  internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
  internal const int TOKEN_QUERY = 0x00000008;
  internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
  public static bool EnablePrivilege(long processHandle, string privilege) {
    bool retVal;
    TokPriv1Luid tp;
    IntPtr hproc = new IntPtr(processHandle);
    IntPtr htok = IntPtr.Zero;
    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
      ref htok);
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = SE_PRIVILEGE_ENABLED;
    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero,
      IntPtr.Zero);
    return retVal;
  }
}
'@  
  $ProcessHandle = (Get-Process -id $pid).Handle
  $type = Add-Type $definition -PassThru
  $type[0]::EnablePrivilege($processHandle, $Privilege)
}

function Take-Over($path) {  
  $owner = [Security.Principal.NTAccount]'Administrators'

  $key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($path, 'ReadWriteSubTree', 'TakeOwnership')
  $acl = $key.GetAccessControl()
  $acl.SetOwner($owner)
  $key.SetAccessControl($acl)

  $acl = $key.getaccesscontrol()
  $rule = New-Object System.Security.AccessControl.RegistryAccessRule "Administrators", "FullControl", "ContainerInherit", "None", "Allow"
  $acl.SetAccessRule($rule)
  $key.SetAccessControl($acl)
}

do {} until (Enable-Privilege SeTakeOwnershipPrivilege)

function Remove-Package($name) {  
  $key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\$name"
  Take-Over $key
  Remove-Item -Path HKLM:"$key\Owners" -Force -Recurse
  & C:\Windows\System32\PkgMgr.exe /up:$name /norestart /quiet
}

#Remove Feedback
$packageBase = "Microsoft-WindowsFeedback"
$packageNames = (dir ("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\" + $packageBase + "*")).name

forEach ($package in $packageNames)
{   
    Remove-Package $package.substring($package.indexOf($packageBase))
}

On using this script, the author remarks :

You can change $packageBase to different package names.

I have not tried this script myself.

EDIT: This script might not work any more, or may need adjustments.


Starting with Windows 10 Anniversary update, Microsoft added a new entry IsInbox in the SQLite database C:\ProgramData\Microsoft\Windows\AppRepository\StateRepository-Machine.srd for the inbox apps. And trying to remove app app flagged as IsInbox fails with 0x80073CFA.

But there is an ugly workaround, that was discovered in April 2017.

You need to download and install the tools ProcessHacker and DB Browser for SQLite.

  • run ProcessHacker 2 as admin, select a C:\Windows\System32\svchost.exe, do a rightclick and select Misc->Run as this user

enter image description here

Now select here C:\Program Files\DB Browser for SQLite\DB Browser for SQLite.exe and start it. In SQLite Browser, click on Open database

enter image description here

and open the file C:\ProgramData\Microsoft\Windows\AppRepository\StateRepository-Machine.srd (change the file type in open dialog to all files to see it).

Now, click on the Browse Data tab, and change the table to Package

enter image description here

Now select the apps you want to remove and change the 1 for the column IsInbox to 0 and save the changes.

enter image description here

repeat this for all apps you want to remove and now the PowerShell commands should work.

But the author writes that Microsoft blocks the upgrade to newer Windows builds if inbox apps are removed. So keep this in mind.


Windows Anniversary update, made quite a few changes that prevents you from turning off certain features, such as cortana or removing apps through official means. Some apps like the xbox app microsoft deemed it as an important app to the system thus preventing official means to remove it.

If you go into the start menu, you can right click it and click uninstall, conversely you can right the start button, go to settings, then apps and features and uninstall it from there.

Now if you are insistent on removing these apps. They are kept in C:\windows\SystemApps So you could find the folder it is kept in and just remove the folder or the safer option is to rename it and add a character such as the underscore _ to the end of the name.

Just to add, if you remove a folder or rename it inside the systemapps folder, this is technically not uninstalling it, rather just forcefully removing it, if you deleted the folder which could leave other stuff installed still like registry keys and other files elsewhere that it uses but not located in the systemapps folder, or forcing it to not run if you renamed the folder.

As Ryakna said in the comments below, using either two of these options can cause problems later down the road, however from my experience I have yet to run into any issues, including updating. But its still recommended to uninstall by official means, either by using powershell if you are familiar with it or through the programs and features option or menu option. The SystemApps folder should not be renamed or deleted, as if you do this, you will most likely encounter problems than if you were to rename or remove a folder inside the systemapps folder.