Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching a Desktop Application with a Metro-style app

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"

like image 809
JacobTheDev Avatar asked Mar 02 '12 03:03

JacobTheDev


People also ask

What is a Metro application?

The Metro Transit app is a quick way to buy tickets for buses and trains and provides you with tools to ride. The app is powered by Token Transit.


2 Answers

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
    }
}
like image 112
Niranjan Singh Avatar answered Sep 27 '22 00:09

Niranjan Singh


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.

like image 29
Christoph Weller Avatar answered Sep 27 '22 00:09

Christoph Weller