PowerShell – Sandbox Testing App Attach Apps – No WVD Required

email me

Use these steps to test your MSIX VHD, without having to use Windows Virtual Desktop. It’s a great way to make sure your MSIX package and MSIX VHD are working properly, and simulate the installation of an app attach application.

 

Microsoft Magic

The magic behind app attach is a mounted VHD (Mount-Diskimage), a file junction (mklink), and a simple app registration (Add-AppxPackage).


Setup

This does assume four things:

  • You’re using a current Insiders build
  • You have a MSIX VHD  (see Step 2 for sample)
  • You have the relative certificate to the MSIX package (see Step 3 for sample)
  • The Hyper-V role has been installed

 

Tested in Windows 10 Build 19041 (it’s best to use one of the latest Insiders’ builds).

Using a VM or a local Windows 10 installation…

 

Steps


Step 1

Create C:\VHD.


Step 2

Copy MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact.vhd to C:\VHD.


Step 3

Copy MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact.cer to C:\VHD.


Step 4

Update the Logon script to reflect your configuration (see code below).


Step 5

Paste Logon script code into PowerShell Console.


Step 6

Verify App was installed.

 

PowerShell Code: Logon script

# MrNetTek
# eddiejackson.net
# 11/7/2020
# free for public use
# free to claim as your own

#import certificate 
cmd.exe /c CERTUTIL.exe -addstore -enterprise -f -v root "C:\VHD\MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact.cer"

#region variables
#side note: these variables could be added to a json file
$VHD = "C:\VHD\MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact.vhd"
$Folder = "Firefox80.0.1"
$Package = "MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact" 
$Folder = "\" + $Folder + "\"
$Volume = "0ab29bd3-b6f6-4f75-a0b5-872ed617dff5" #mountvol.exe
$Junction = "C:\AppAttachTmp\" 
#endregion 

#region mountvhd
try 
{
    Mount-Diskimage -ImagePath $VHD -NoDriveLetter -Access ReadOnly
    Write-Host ("Mounting of " + $VHD + " was completed!") -BackgroundColor Green 
}
catch
{
    Write-Host ("Mounting of " + $VHD + " has failed!") -BackgroundColor Red
}
#endregion
 
#region junction
$Destination = "\\?\Volume{" + $Volume + "}\"
if (!(Test-Path $Junction)) 
{
    md $Junction
}
$Junction = $Junction + $Package
cmd.exe /c mklink /j $Junction $Destination
#endregion
 
#region stage
[Windows.Management.Deployment.PackageManager,Windows.Management.Deployment,ContentType=WindowsRuntime] | Out-Null
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where { $_.ToString() -eq 'System.Threading.Tasks.Task`1[TResult] AsTask[TResult,TProgress](Windows.Foundation.IAsyncOperationWithProgress`2[TResult,TProgress])'})[0]
$asTaskAsyncOperation = $asTask.MakeGenericMethod([Windows.Management.Deployment.DeploymentResult], [Windows.Management.Deployment.DeploymentProgress])
$PackageManager = [Windows.Management.Deployment.PackageManager]::new()  
$Path = $Junction + $Folder + $Package 
$Path = ([System.Uri]$Path).AbsoluteUri
  $asyncOperation = $packageManager.StagePackageAsync($Path, $null, "StageInPlace")                                                                                                                
$Task = $asTaskAsyncOperation.Invoke($null, @($asyncOperation))    
$Task
#endregion
 
 
#region variables 
#FIREFOX
$Package = "MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact" 
$Path = "C:\Program Files\WindowsApps\" + $Package + "\AppxManifest.xml"
#endregion

#region register
Add-AppxPackage -Path $Path -DisableDevelopmentMode -Register
#endregion

exit 0

 

 

Output

 

 

 

Notes

 

PowerShell Code: Logoff script

#region variables
$Package = "MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact"
#endregion

#region deregister
Remove-AppxPackage -PreserveRoamableApplicationData $Package
#endregion
 

#MSIX app attach de-staging
#region variables
$Package = "MozillaFirefox80.0.1x64en-US_80.0.1.0_x64__1z5jebwm3hact"
$Junction = "C:\AppAttachTmp\"
#endregion


#region deregister
Remove-AppxPackage -AllUsers -Package $Package
cd $Junction
rmdir $Package -Force -Verbose
#endregion