4

I tried to launch the UWP application from c# console application. It tried with below code which uses APPID

Process.Start(@"C:\Program Files (x86)\Windows Kits\10\App Certification Kit\microsoft.windows.softwarelogo.appxlauncher.exe", "1a75- 6f75 - 5ed3 - 8944 - 6b7df2bee095");

Is there any better way to launch UWP application programatically.

Subrak
  • 139
  • 11

3 Answers3

4

To launch any UWP app on the system you can use the following API:
AppListEntry.LaunchAsync Method

To get the AppListEntry for the desired application, use the PackageManager APIs: PackageManager.FindPackageForUser(String, String) Method
Package.GetAppListEntriesAsync Method

Alternatively, you can use the following Win32 API insteadp of the AppListEntry API:
IApplicationActivationManager::ActivateApplication method

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
  • @ispiro Yes, I do. I am currently on vacation so I can't follow up internally myself. That's why I asked him. LinkedIn search may point you to a different person with same name. – Stefan Wick MSFT Jul 14 '19 at 23:45
  • @stefan-wick-msft Is there a way to get the process .exe name from a package? After launching it seems there's no way to monitor the running process without it. – Sean O'Neil Aug 11 '22 at 13:30
2

And when your console application is written in some exotic languages, for example Java, you can do something like

enter image description here

https://www.c-sharpcorner.com/article/launch-uwp-app-via-commandline/ For better results do omit these two attributes:

  <!--  Executable="$targetnametoken$.exe"
    EntryPoint="$targetentrypoint$"-->

Then carry on as described here.

kellogs
  • 2,837
  • 3
  • 38
  • 51
1

I tried to launch the UWP app through Protocol. The below link will help how to create a protocol

Automate launching Windows 10 UWP apps

Now you can launch your application by using

Process.Start("URL:myapplication://");

The process class is available in System.Diagnostics. And also need to add the following method in App.xaml.cs file

 protected override void OnActivated(IActivatedEventArgs args)
    {
        Initialize(args);
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;


                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            // Always navigate for a protocol launch
            rootFrame.Navigate(typeof(MainPage), eventArgs.Uri.AbsoluteUri);


            // Ensure the current window is active
            Window.Current.Activate();
        }

    }
Subrak
  • 139
  • 11