5 minutes reading time (1051 words)

Starting MSIX and AppX packages with PowerShell from the command line

MSIX_ZOOM

Microsoft Store applications (or Modern Applications) have now become standard on the desktop. Many users don't want to limit themselves any more and so the calculator on the terminal server should look exactly like the calculator on their own Windows 10 desktop. Sometimes you want to use your own "launcher" for an application. For example to start a script with the start of the application to import registry keys or connect network drives.For Microsoft Store applications (or Modern Applications) have now become standard on the desktop. Many users don't want to limit themselves any more and so the calculator on the terminal server should look exactly like the calculator on their own Windows 10 desktop. Sometimes you want to use your own "launcher" for an application. For example to start a script with the start of the application to import registry keys or connect network drives.

In such a case, a "Modern Application" must also be started from the command line. Well, a look at the calculator's start menu icon shows that this is not that easy. The icon there has no properties. Neither in the user folder of the start menu nor in the system folder there is a shortcut (C:\ProgramData\Microsoft\Windows\Start Menu\Programs \*.lnk). Since Windows 8 the icons for the Modern Applications are processed differently than usual.Therefore you can find some blogs about "How to start these applications with the console". Unfortunately they are often very complicated and difficult to understand. The simplest way is to create a real ".lnk" shortcut for calling them from the command line.

For this:

1. in the Explorer Shell:Enter AppsFolder

2. go to the icon with the right mouse button and select "Create shortcut

ShellAppsFolder

The shortcut is created directly on the desktop and can of course be moved. You can also use the shortcut to extract the icon.The shortcut is created directly on the desktop and can of course be moved. You can also use the shortcut to extract the icon.The start via the command line (PowerShell) can now be done with the following command (adjust paths if necessary):

& "$env:USERProfile\Desktop\Calculator - Shortcut.lnk"
#
# Or
#
start-Process "$env:USERProfile\Desktop\Calculator - Shortcut.lnk"
#
#Extracting the symbol is possible as follows:
#
Add-Type -AssemblyName System.Drawing
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("$env:USERProfile\Desktop\Calculator - Shortcut.lnk")
$Icon.ToBitmap().Save("$env:USERProfile\Desktop\Calculator- Shortcut.bmp")

That was the simple way, the complex way is to look into the package manifest, read it and then build a call using Explorer.exe. So Explorer.Exe Shell:AppsFolder:<ApplicationID>!<AppID>That was the simple way, the complex way is to look into the package manifest, read it and then build a call using Explorer.exe. So

Explorer.Exe Shell:AppsFolder:<ApplicationID>!<AppID>

Now I wanted to simplify exactly this call and so I built a PowerShell OneLiner to search for the parameters and call the AppX application. It looks with wildcard for the package *<NAME>*. searches for the AppID and starts the application. In the following MSPaint3d and the calculator.

Attention: You must be careful with the call. A call *Microsoft* tries to start 113 applications.

#Start Paint3d
Get-AppxPackage *mspaint* | % {& Explorer.exe $('Shell:AppsFolder\' + $_.PackageFamilyName + ‚!' + $((Get-AppxPackageManifest $_.PackageFullName).Package.Applications.Application.id))} 
#Start the Calculator
Get-AppxPackage *calc* | % {& Explorer.exe $(‚Shell:AppsFolder\' + $_.PackageFamilyName + ‚!' + $((Get-AppxPackageManifest $_.PackageFullName).Package.Applications.Application.id))}

Now you might want to use the commandline via a shortcut. So by calling Powerchell.exe. The following one-liners (or for shortcuts):

& Powershell.exe -Command '& {param($pname) Get-AppxPackage "*$pname*" | % { &explorer.exe $($("""Shell:AppsFolder\\""") + $_.PackageFamilyName + """!""" + $((Get-AppxPackageManifest $_.PackageFullName).Package.Applications.Application.id)) }}' "Paint"
& Powershell.exe -Command '& {param($pname) Get-AppxPackage "*$pname*" | % { &explorer.exe $($("""Shell:AppsFolder\\""") + $_.PackageFamilyName + """!""" + $((Get-AppxPackageManifest $_.PackageFullName).Package.Applications.Application.id)) }}' "Calc"

As we are already there, I thought about creating a commandline tool for it. The ISE steroids have a tremendous capability for this. The script shouldn't take a lot of time, I just wanted to write a new blog on the fly. But it should still catch errors. Here is the PowerShell script.

[CmdletBinding()]
Param(
  [Parameter(Mandatory=$true)] [String] $ShortAppname,
  [int] $AppID = 0
)
  
<#
    .Synopsis
    Start a AppX Application
    .DESCRIPTION
    Start a AppX Application
    .EXAMPLE
    Start-Appx Calc #Start the calculator app
#>
  
function Start-AppXApplication
{
  [CmdletBinding()]
  
  param(      [Parameter(Mandatory=$true)][String] $ShortAppname,
    [int] $AppID = 0
  )
  Process
  {
    Write-Output "Andreas Nick 2020 - https://www.andreasNick.com"     Write-Output "Start-AppXApplication [-ShortAppname] <String> [[-AppID] <Int32>]`n"    
    if($ShortAppname.Length -le 3 ) {       Write-Warning "The name must have at least four characters"     } else {
      $AppXPackages = @(Get-AppxPackage *$ShortAppname*)
      if($AppXPackages.Count -gt 1) {
        Write-Warning "To may results for $ShortAppname :$($AppXPackages.Count) - abort"
      } else  {
  
        $AppXPackages | Select-Object -First 1 | ForEach-Object {
          $AppIDs =  @($((Get-AppxPackageManifest $_.PackageFullName).Package.Applications.Application)) #[$AppID].id
          Write-Verbose ($AppIDs | Out-String)
          if(-not ($AppIDs[$AppID].id)){
            Write-Warning "Id $AppID not exist"           } <br>           else{
              Start-Process Explorer.exe -ArgumentList $('Shell:AppsFolder\' + $_.PackageFamilyName + '!' +  $AppIDs[$AppID].id)
          }
        } 
      }
    }
  }
}

 Unfortunately there were problems with the output first. Toboas Welter, the author of the ISE-Steroids  could help me soon (Link: Whoever wants to buy it - I can highly recommend the steroids):

Tobias

There are now two versions in the archive (download below). A version with text output in the console and a version without. Because with the text output another window appears for a short time. The call is done with a shortcut for the app, for example Calc for the calculator. The full AppX name for the calculator is "Microsoft.WindowsCalculator". Since some AppX applications can contain more than one app, an ID can be passed as a second parameter. If you use the version with error output, an unknown ID would be reported and the AppX application would not start.There are now two versions in the archive (download below). A version with text output in the console and a version without. Because with the text output another window appears for a short time. The call is done with a shortcut for the app, for example Calc for the calculator. The full AppX name for the calculator is "Microsoft.WindowsCalculator". Since some AppX applications can contain more than one app, an ID can be passed as a second parameter. If you use the version with error output, an unknown ID would be reported and the AppX application would not start.

.\Start-AppXApplicationHideOutput.exe *Com* # starts Windows Mail

.\Start-AppXApplicationHideOutput.exe *Com* 1 # starts the calendar in the Mail App

By the way, the application name here is "MicrosoftCommunicator" - hence the abbreviation "com" worksSome examples in the following screenshot:

AppxLauncher

 Download (executable and PowerShell script)

Files:

AppXLauncher

Information
Created 07.08.2020 11:55:53
Changed
Version 1.0
Size 123.77 KB
Created by Andreas Nick
Changed by
Downloads 5
License Nick Informationstechnik Tool LicenceTooltip
Price

 

SQL Server Management Studio 18.5 (SSMS) App-V Rec...
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
Monday, 28 September 2020

Captcha Image

@nickinformation Tweets

My german Blog: 

http://www.software-virtualisierung.de

in 

Cookies make it easier for us to provide you with our services. With the usage of our services you permit us to use cookies.
More information