Launching a Desktop Application with a Metro-style app
Asked Answered
A

5

15

Is there a way to launch a desktop application from a Metro-style app on Windows 8? I'm trying to create some simple shortcuts to desktop applications to replace the desktop icons on the start screen, which look out of place.

I just need something super simple, preferably in C#, to open an application as soon as the app loads. I'm planning on making these shortcuts for some games, photoshop, etc, not anything I've made myself. They're also just for personal use, so I can use direct paths to applications like "C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe"

Alfeus answered 2/3, 2012 at 3:39 Comment(3)
You can't launch desktop apps (or other processes in general), due to sandbox. The best you can do is "launch" a file or URI, such that the associated default program - which may be a desktop app - is launched.Crustacean
"Launch" the URI, you mean? You use Windows.System.Launcher class for that, specifically the LaunchUriAsync method. It was given in one of the replies below.Crustacean
A similar question was posted here. My proposed answer to that question also applies to this questionChalco
H
21

If you simply want to run a desktop application like (notepad, wordpad, internet explorer etc) then go through Process Methods and ProcessStartInfo Class

try
{
// Start the child process.
    Process p = new Process();
    // Redirect the output stream of the child process.
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = "C:\Path\To\App.exe";
    p.Start();
}

// Exp 2

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.WindowStyle = ProcessWindowStyle.Minimized;

    Process.Start(startInfo);

    startInfo.Arguments = "www.northwindtraders.com";

    Process.Start(startInfo);
}

On Windows 8 Metro application i discovered this: How to Start a external Program from Metro App.

All the Metro-style applications work in the highly sand boxed environment and there is no way to directly start an external application.

You can try to use Launcher class – depends on your need it may provide you a feasible solution.

Check this:
Can I use Windows.System.Launcher.LauncherDefaultProgram(Uri) to invoke another metro style app?

Ref: How to launch a Desktop app from within a Metro app?

Metro IE is a special app. You cannot invoke an executable from Metro style apps.

Try this - I have not test yet but may be it will help you..

Launcher.LaunchFileAsync

// Path to the file in the app package to launch
string exeFile = @"C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe";

var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(exeFile);

if (file != null)
{
    // Set the option to show the picker
    var options = new Windows.System.LauncherOptions();
    options.DisplayApplicationPicker = true;

    // Launch the retrieved file
    bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
    if (success)
    {
       // File launched
    }
    else
    {
       // File launch failed
    }
}
Hose answered 2/3, 2012 at 5:13 Comment(2)
Thanks, I'll take a whack at it when I get home from work, and probably accept your answer then. The ugly legacy icons on the start screen get on my nerves, so this really helps.Alfeus
The first one looks like what I'm looking for, but I keep getting an error on "Process."Alfeus
A
12

I found a solution which is suitable for me. I just made an empty textfile in my app and called it launcher.yourappyouwanttostart and then executed it with

Windows.System.Launcher.LaunchFileAsync("launcher.yourappyouwanttostart");

On the first startup it asks you for the assocation for this file and then you choose the exe file you want to run and from now on every time you execute this file, your app will be started.

Arnett answered 26/8, 2012 at 7:14 Comment(1)
Haha, oh wow. +1 I'm going to have to remember this for LOB internal-use applications.Pipsqueak
C
3

I haven't actually tried if it works and it's not really a beautiful solution, but I guess Metro-style apps can launch a URI. You could then create a desktop-program that is registered for a custom URI scheme that would then do the actual program launching.

Copacetic answered 5/3, 2012 at 0:52 Comment(0)
C
1

What you can do is host external WCF service on your computer with separate installation and connect to it from metro style application using localhost. Then you can do pretty much anything including Process.Start.

Contradictory answered 8/7, 2012 at 5:28 Comment(2)
Could you explain this more clearly please? What is an external WCF service and what do you mean by "with separate installation"?Curzon
Windows Communication Foundation. You'd be able to communicate through the service to the App and invoke things that way. Whilst this is a solution I'd recommend, it's not worth reading up for the sole purposes of solving this problem. Take the hacky route for now, ha. But deffo read up on WCF, great platform I use it mostly for sending data over the web (REST/SOAP etc)Impious
H
0

I love simple things, so my solution was to use this:

Process.Start("explorer", "shell:AppsFolder\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe!App")

This will start the "new" Sticky Notes coming with Anniversary Update to Windows 10, but it works with all other "Metro" apps I tested. To find the name of the metro app, from Windows Explorer you have to find it in shell:appsfolder using the AppUserModelId column.

Hughes answered 27/8, 2016 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.