Tomas1856
Posts: 4
Joined: Fri Jan 29, 2016 10:10 am

Cannot remove AppX via Remove-AppxPackage, due different SID

Thu Feb 04, 2016 10:00 am

Hi,

I am trying to setup an automated test framework using Raspberry with 10.0.10586.63. Here's a short list what steps it performs:
* Copy AppX to Raspberry. For ex.,
Copy RuntimeTests_1.0.0.0_ARM_Debug from C:\Tests\RuntimeTests_1.0.0.0_ARM_Debug.appx to \\minwinpc1\c$\Tests\RuntimeTests_1.0.0.0_ARM_Debug.appx
* Use powershell's Invoke-Command -ComputerName minwinpc1 -Credential <credentials> to execute commands remotely
- Get-AppxPackage Run* | Remove-AppxPackage (to ensure no previous packages are installed)
- Add-AppXPackage C:\Tests\RuntimeTests_1.0.0.0_ARM_Debug.appx to install new package
- Run the appx

My problem is with Get-AppxPackage Run* | Remove-AppxPackage, sometimes it fails with error

Code: Select all

Remove-AppxPackage : Deployment failed with HRESULT: 0x80073CF1, Package was not found.
Windows cannot remove RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg because the current user does not have that package
installed. Use Get-AppxPackage to see the list of packages installed.
NOTE: For additional information, look for [ActivityId] a5d4034b-5e95-0000-ed51-d4a5955ed101 in the Event Log or use
the command line Get-AppxLog -ActivityID a5d4034b-5e95-0000-ed51-d4a5955ed101
    + CategoryInfo          : ObjectNotFound: (RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg:String) [Remove-AppxPackage], P
   SInvalidOperationException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand
But believe me, the package is installed.

I tracked this issue to different SID assigned to app when it's installed, for ex when executing Get-AppxPackage Run* -Allusers

Code: Select all

Name                   : RuntimeTests
Publisher              : CN=DefaultCompany
Architecture           : Arm
ResourceId             :
Version                : 1.0.0.0
PackageFullName        : RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg
InstallLocation        : C:\Data\Programs\WindowsApps\RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg
IsFramework            : False
PackageFamilyName      : RuntimeTests_pzq3xp76mxafg
PublisherId            : pzq3xp76mxafg
PackageUserInformation : {S-1-5-21-2702878673-795188819-444038987-500 [S-1-5-21-2702878673-795188819-444038987-500]:
                         Installed}
IsResourcePackage      : False
IsBundle               : False
IsDevelopmentMode      : False
Note PackageUserInformation, sometimes it's different, the other time it might be S-1-5-21-2702878673-795188819-444038987-503, that's when Get-AppxPackage Run* | Remove-AppxPackage will fail.

I don't much about these security identifiers, but can I somehow ensure that it's always the same, or maybe there are some other control mechanisms for this?

Or is there a way to Remove-AppxPackage for all users.

Any help would be appreciated
Last edited by Tomas1856 on Thu Feb 04, 2016 3:24 pm, edited 1 time in total.

Tomas1856
Posts: 4
Joined: Fri Jan 29, 2016 10:10 am

Re: Cannot remove AppX via Remove-AppxPackage, due different

Thu Feb 04, 2016 1:45 pm

Some update

Code: Select all

$objSID = New-Object System.Security.Principal.SecurityIdentifier ("S-1-5-21-2702878673-795188819-444038987-503") 
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount]) 
$objUser.Value
minwinpc1\DefaultAccount is returned

Code: Select all

$objSID = New-Object System.Security.Principal.SecurityIdentifier ("S-1-5-21-2702878673-795188819-444038987-500") 
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount]) 
$objUser.Value
minwinpc1\Administrator is returned

It seems, after Add-AppxPackage, the package belongs only to minwinpc1\Administrator, but after running the application at least once, a new ownership is assgined, or I should say added:

Code: Select all

Name                   : RuntimeTests
Publisher              : CN=DefaultCompany
Architecture           : Arm
ResourceId             :
Version                : 1.0.0.0
PackageFullName        : RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg
InstallLocation        : C:\Data\Programs\WindowsApps\RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg
IsFramework            : False
PackageFamilyName      : RuntimeTests_pzq3xp76mxafg
PublisherId            : pzq3xp76mxafg
PackageUserInformation : {S-1-5-21-2702878673-795188819-444038987-500 [S-1-5-21-2702878673-795188819-444038987-500]:
                         Installed, S-1-5-21-2702878673-795188819-444038987-503
                         [S-1-5-21-2702878673-795188819-444038987-503]: Installed}
IsResourcePackage      : False
IsBundle               : False
IsDevelopmentMode      : False
After, I can no longer remove appx with Remove-AppxPackage, the only way to remove it - is via WebBrowser :(

Tomas1856
Posts: 4
Joined: Fri Jan 29, 2016 10:10 am

Re: Cannot remove AppX via Remove-AppxPackage, due different

Fri Feb 05, 2016 9:33 am

So I found a way, it's not pretty but it works!
By sniffing what the web browser sends to Raspberry I was able to figure the command for deleting app for DefaultAccount

From PC, I execute this command via Powershell

Code: Select all

Invoke-WebRequest  http://minwinpc:8080/api/app/packagemanager/package?package=RuntimeTests_1.0.0.0_arm__pzq3xp76mxafg -Method Delete -cred <Credentials>

Return to “Windows 10 for IoT”