Categories: Opinion

Windows Sandbox – How to install Windows Store apps

The Windows Sandbox image is useful for many test setups, but it lacks much of the usual UI Windows experience, including all of Windows Store apps (and the Windows Store itself).

So here’s how you can install these apps using Powershell. We’ll be using a Powershell script found on Github (here) to make the process of downloading the apps easier.

So first, copy the script to your clipboard:

function Download-AppxPackage {
[CmdletBinding()]
param (
  [string]$Uri,
  [string]$Path = "."
)
   
  process {
    echo ""
    $StopWatch = [system.diagnostics.stopwatch]::startnew()
    $Path = (Resolve-Path $Path).Path
    #Get Urls to download
    Write-Host -ForegroundColor Yellow "Processing $Uri"
    $WebResponse = Invoke-WebRequest -UseBasicParsing -Method 'POST' -Uri 'https://store.rg-adguard.net/api/GetFiles' -Body "type=url&url=$Uri&ring=Retail" -ContentType 'application/x-www-form-urlencoded'
    $LinksMatch = ($WebResponse.Links | where {$_ -like '*.appx*'} | where {$_ -like '*_neutral_*' -or $_ -like "*_"+$env:PROCESSOR_ARCHITECTURE.Replace("AMD","X").Replace("IA","X")+"_*"} | Select-String -Pattern '(?<=a href=").+(?=" r)').matches.value
    $Files = ($WebResponse.Links | where {$_ -like '*.appx*'} | where {$_ -like '*_neutral_*' -or $_ -like "*_"+$env:PROCESSOR_ARCHITECTURE.Replace("AMD","X").Replace("IA","X")+"_*"} | where {$_ } | Select-String -Pattern '(?<=noreferrer">).+(?=</a>)').matches.value
    #Create array of links and filenames
    $DownloadLinks = @()
    for($i = 0;$i -lt $LinksMatch.Count; $i++){
        $Array += ,@($LinksMatch[$i],$Files[$i])
    }
    #Sort by filename descending
    $Array = $Array | sort-object @{Expression={$_[1]}; Descending=$True}
    $LastFile = "temp123"
    for($i = 0;$i -lt $LinksMatch.Count; $i++){
        $CurrentFile = $Array[$i][1]
        $CurrentUrl = $Array[$i][0]
        #Find first number index of current and last processed filename
        if ($CurrentFile -match "(?<number>\d)"){}
        $FileIndex = $CurrentFile.indexof($Matches.number)
        if ($LastFile -match "(?<number>\d)"){}
        $LastFileIndex = $LastFile.indexof($Matches.number)

        #If current filename product not equal to last filename product
        if (($CurrentFile.SubString(0,$FileIndex-1)) -ne ($LastFile.SubString(0,$LastFileIndex-1))) {
            #If file not already downloaded, add to the download queue
            if (-Not (Test-Path "$Path\$CurrentFile")) {
                "Downloading $Path\$CurrentFile"
                $FilePath = "$Path\$CurrentFile"
                $FileRequest = Invoke-WebRequest -Uri $CurrentUrl -UseBasicParsing #-Method Head
                [System.IO.File]::WriteAllBytes($FilePath, $FileRequest.content)
            }
        #Delete file outdated and already exist
        }elseif ((Test-Path "$Path\$CurrentFile")) {
            Remove-Item "$Path\$CurrentFile"
            "Removing $Path\$CurrentFile"
        }
        $LastFile = $CurrentFile
    }
    "Time to process: "+$StopWatch.ElapsedMilliseconds
  }
}


if (-Not (Test-Path "C:\Support\Store")) {
    Write-Host -ForegroundColor Green "Creating directory C:\Support\Store"
    New-Item -ItemType Directory -Force -Path "C:\Support\Store"
}

Open a Powershell window with Administrator privileges; paste the script in the command line and press Enter.

The script will accept two variables, in this order:

  • App URL: this is the Windows Store URL E.g.
    https://www.microsoft.com/en-us/p/snip-sketch/9mz95kl8mr0l?activetab=pivot:overviewtab
  • Download location: if left empty, by default Apps will be stored in “C:\Support\Store”

To download an app, just browse to its Windows Store page and copy the link (note that it will matter which language you’re browsing in):

Download-AppxPackage "<a rel="noreferrer noopener" href="https://www.microsoft.com/en-us/p/snip-sketch/9mz95kl8mr0l?activetab=pivot:overviewtab" data-type="URL" data-id="https://www.microsoft.com/en-us/p/snip-sketch/9mz95kl8mr0l?activetab=pivot:overviewtab" target="_blank">https://www.microsoft.com/en-us/p/snip-sketch/9mz95kl8mr0l</a>" "C:\Support\Store"

After that, you’ll need to run the installer, using the downloaded file, as such:

Add-AppxPackage C:\Support\Store\Microsoft.ScreenSketch_2020.814.2355.0_neutral_~_8wekyb3d8bbwe.appxbundle

Note that you will probably need to install these packages first as well:

Microsoft.UI.Xaml.(...).appx

Microsoft.VCLibs.(...).appx

sete

Recent Posts

Synology – Modify public link metadata (site description and keywords)

If you have a Synology DiskStation and you have shared your public NAS link on…

4 years ago

Ubuntu Linux VM on Hyper-V – Expand Virtual disk to full size

Ubuntu initial setup does not do expand the virtual disk image to it's full size.…

4 years ago

Synology DSM 7 Docker error – Container crashes on boot – Solution / Fix

A common issue that appeared with DSM 7 is that some well known containers started…

4 years ago

Windows 10 Snip & Sketch app fails – “Failed to open the file” error fix

If you're used to Snip & Sketch for adding some scribbles placed over desktop screenshots,…

6 years ago

How to solve “Contacting the server for information” in Microsoft / Office 365 apps

On some occasions Microsoft 365 Office applications might open a popup with "Contacting server for…

6 years ago

Here are Chocolatey’s common commands – Windows command line Package Manager

You might have already heard about Chocolatey, a package manager similar to apt-get in linux…

6 years ago