Waqas Ahmed Khan
Waqas Ahmed Khan

Reputation: 353

How to launch a desktop application from windows store apps?

Please tell me how we can launch a desktop application or .exe file from a Windows store app using c#.

Any help would be really appreciated. Thanks in Advance!

Upvotes: 1

Views: 1159

Answers (1)

Dustin Cleveland
Dustin Cleveland

Reputation: 618

As stated in the comments, you can't directly launch an executable from a Windows Store App because of the sandboxed environment. However, you can use the launcher API to start an executable associated with a file. Therefore, you could create a file association between a custom file extension and the application you want to launch. Then, just use the launcher API to open a file having the custom file extension.

public async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images\test.png";

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

   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
   }
}

Upvotes: 2

Related Questions