Launching a Windows 10 UWP app from the command line cmd
Asked Answered
N

4

9

I would like to be able to launch a Windows 10 UWP app from a single command line (cmd Windows 10) input. I am having issues concatenating the strings together to form the entire package name (this needs to be dynamic because the ending string of the app can change with each deployment). Here is the logic I have:

  1. Find the app package name in the LocalAppData directory (i.e. packageName_postfix)
  2. Append "!App" to the end of the result in #1
  3. Pass that string into the launch function:

I have gotten to a point where I can find #1, but for some reason when I try to append it to #2, I get a NULL value. Here is my current command:

1.) & 2.): Get Package Name and Append it to "!App"

set "x=|dir %LocalAppData%\Packages /b | findstr packageName" & set "y=!App" & set "z=%x%%y%" & echo.%z%

3.): Launch UWP App

explorer.exe shell:appsFolder\packageName_postfix!App

Any ideas?

Neptune answered 18/8, 2018 at 18:14 Comment(2)
shell:appsFolder is a command not a path component.Rubenrubens
Also note that the id to be appended may not always be !App.Tropophilous
D
11

First you must know this solution only work on Windows 10 Fall Creators Update and newer versions. This API will support Windows Insider Build version 16266 or greater.

Add this namespace in Pacakge.appxmanifest file :

xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"  

Then add this extension :

<Extensions>  
    <uap5:Extension   
      Category="windows.appExecutionAlias"   
      Executable="MyApp.exe"   
      EntryPoint="MyApp.App">  
      <uap5:AppExecutionAlias>  
        <uap5:ExecutionAlias Alias="MyApp.exe" />  
      </uap5:AppExecutionAlias>  
    </uap5:Extension>  
  </Extensions>  
  • Executable name - Application.Exe name (Ex: MyApp.exe)
  • EntryPoint - Entrypoint tag should contain the Full name of the application class(Ref: open -> App.xaml file -> Application x: Class name)
  • AppExecutionAlias - Type alias name in command prompt to open the application; give the app.exe name as alias name.

Build the application and run it one time!

Open command Prompt, type the alias name -> Enter

You can also see the reference Here

Diet answered 19/8, 2018 at 4:8 Comment(2)
What do you mean by "Build the application". What if I don't have the source code of the application (and I don't have the source code of any the my UWP apps I use). What exactly should I build here?Aggravate
@mar: Stack Overflow is for developers. If you are looking for a solution targeted at users, try superuser instead.Marmolada
L
3

SO with this step!

explorer.exe shell:appsFolder\**packageName_postfix**!**App**

how to get packageName_postfix and App?

go to Win+R >> shell:appsFolder create shortcut for your app on desktop (right click) after try properties on shortcut and copy path of it.

finnaly win+r explorer.exe shell:appsFolder\Microsoft.ZuneMusic_8wekyb3d8bbwe!Microsoft.ZuneMusic

Louis answered 18/4, 2021 at 6:9 Comment(0)
T
0

Adding some "pure command-line methods" using PowerShell. These can be assembled into a general-purpose script for finding the launch mechanism, but it's easier to explain the individual components below without "putting it all together" at once.

First, note that you may not need the explorer.exe method any longer. Many recent UWP apps now include an app execution alias for command-line access. Since this feature was introduced about 5 years ago now, it's available in all supported builds of Windows 10 and 11.

The starting point for finding the launch command is always going to be the AppxPackage itself. But sometimes finding the package can be more difficult than others:

  • The "easy" case -- Just filter Get-AppxPackage's return results for one matching the Name. Using Windows Terminal as an example:

    Get-AppxPackage |? { $_.Name -like "*Terminal*" } | tee-object -Variable packageMatches
    
  • However, some apps are oddly named. For instance, the Minecraft Dungeons package name is Microsoft.Lovika, which I assume was its project name during development. Unless you know what you are looking for, you may want to perform a (slower) search based on the manifest DisplayName:

    Get-AppxPackage |? {
        (Get-AppxPackageManifest -Package $_.PackageFullName).Package.Properties.DisplayName -like "*Mine*" 
    } | tee -variable packageMatches
    

Once you have the $packageMatches result, you can use one of two different ways to find how to launch it:

  • Using the fully-qualified path to the app execution alias, if one is available. To determine this:

    $packageMatches |% {
        $executableName = ((Get-AppxPackageManifest -Package $_.PackageFullName).Package.Applications.Application.Executable)
        if ($executableName) {
            "Start-Process ""$($_.InstallLocation)\$executableName"""
        } else {
            "No executable found"
        }
    }
    

    Note: The Start-Process format that this returns is simply for launching from PowerShell with simplified quoting rules for paths-with-spaces. Adapt as needed for other launchers.

  • If there is no app execution alias for the app, you can fall back to using the explorer.exe shell:appsFolder\<PackageFamilyName>!<Id> method covered in other answers. To obtain the correct name and id:

    $packageMatches |% {
        "explorer.exe shell:appsFolder\$($_.PackageFamilyName)!$((Get-AppxPackageManifest -Package $_.PackageFullName).Package.Applications.Application.Id)"
    }
    

    For example, any PWA (progressive web app) or website installed through Edge as an application will be not have an executable, but will be launchable through explorer.exe.

Tropophilous answered 21/11, 2022 at 2:40 Comment(0)
S
0

It's possible creating a shortcut (.lnk file) and then shell execute the shortcut, this might not be perfect solution but at least should be very fast, using PowerShell for instance needs at least 250 ms for startup, and also shows a console window, which might be unwanted. There is a tool that can hide the console window: run-hidden.

It's also a very simple solution anybody can use, does not require authoring and learning a complex script or app, simple solutions are sometimes overlooked.

Smitten answered 22/11, 2022 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.