C# launching an external app with metro api

0

I am trying to develop an app which launches a regular .exe application from metro app using launcher class. MSDN provided a sample here and a stackoverflow sample is here

The problem is that my metro gives error of "file not found" even the file is there. i have tried to place file on other drives as well but the problem persists

here is my code sample

// Path to the file in the app package to launch
string imageFile = @"E:\App.exe"; 

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

/* error in the above line .it says file not found The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)*/

if (file != null)
{
    // Launch the retrieved file
    var success = await Windows.System.Launcher.LaunchFileAsync(file);

    if (success)
    {
        // File launched

    }
    else
    {
        // File launch failed
    }
}
else
{
    // Could not find file
}
c#
asked on Stack Overflow May 20, 2013 by Umair • edited May 23, 2017 by Community

1 Answer

3

LaunchFileAsync is for launching a file in its default program.

http://msdn.microsoft.com/library/windows/apps/Hh701461

I am not convinced it will work with an .exe

The correct usage is something like:

LaunchFileAsync("images\\picturesofcats.png"); 

This then opens a picture of cats in your default image viewer.

This will not work for an .exe due to sandboxing, and because .exe has no default opener.

There are a few tricks to get around this, see: Launching a Desktop Application with a Metro-style app

Generally, you are working against the design of Windows 8 to do this, so you might want to reconsider your approach.

answered on Stack Overflow May 20, 2013 by KingCronus • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0