Launcher Launcher Launcher Launcher Launcher Class

Definition

Starts the default app associated with the specified file or URI.

public : static class Launcher
static struct winrt::Windows::System::Launcher
public static class Launcher
Public Static Class Launcher
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

Launch a file contained in the app packageThis example uses LaunchFileAsync(IStorageFile) | launchFileAsync(IStorageFile) to launch a file contained in the app package.


// Path to the file in the app package to launch
var imageFile = "images\\test.png";

// Get the image file from the package's image directory
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(imageFile).then(
  function (file) {
    // Launch the retrieved file using the default app
    Windows.System.Launcher.launchFileAsync(file).then(
      function (success) {
        if (success) {
            // File launched
        } else {
            // File launch failed
        }
      });
  });
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
   }
}
async Sub DefaultLaunch()

   ' Path to the file in the app package to launch
   Dim imageFile = "images\test.png"

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

   If file IsNot Nothing Then
      ' Launch the retrieved file
      Dim success = await Windows.System.Launcher.LaunchFileAsync(file)

      If success Then
         ' File launched
      Else
         ' File launch failed
      End If
   Else
      ' Could not find file
   End If
End Sub
void MainPage::DefaultLaunch()
{
   auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

   concurrency::task<Windows::Storage::StorageFile^> getFileOperation(installFolder->GetFileAsync("images\\test.png"));
   getFileOperation.then([](Windows::Storage::StorageFile^ file)
   {
      if (file != nullptr)
      {
         // Launch the retrieved file
         concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file));
         launchFileOperation.then([](bool success)
         {
            if (success)
            {
               // File launched
            }
            else
            {
               // File launch failed
            }
         });
      }
      else
      {
         // Could not find file
      }
   });
}

Launch a URIThis example uses LaunchUriAsync(Uri) | launchUriAsync(Uri) to launch a URI.


// The URI to launch
var uriToLaunch = "http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Windows.Foundation.Uri(uriToLaunch);

// Launch the URI
Windows.System.Launcher.launchUriAsync(uri).then(   
   function (success) {
      if (success) {
        // URI launched
      } else {
        // URI launch failed
      }
   });
// The URI to launch
string uriToLaunch = @"http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Uri(uriToLaunch);

// Launch the URI
async void DefaultLaunch()
{
   // Launch the URI
   var success = await Windows.System.Launcher.LaunchUriAsync(uri);

   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
' The URI to launch
Dim uri As New Uri("http://www.bing.com")

async Sub DefaultLaunch()

   ' Launch the URI
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri)

   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If

End Sub
// The URI to launch
auto uri = ref new Windows::Foundation::Uri("http://www.bing.com");

void MainPage::DefaultLaunch()
{
   // Launch the URI
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}

Launch with a warning dialogCall launchUriAsync(Uri, LauncherOptions) to launch a URI with a warning. Use the treatAsUntrusted property to indicate that the system should display a warning.

Note

For Windows app using JavaScript, call preventDefault in your event handler if the treatAsUntrusted property is set and you are using an a element to launch the URI.

function linkClickHandler(eventInfo) {
    var link = eventInfo.target;
    if (eventInfo.srcElement && (
        (eventInfo.type === "click") ||
        (eventInfo.type === "keydown" && (
        eventInfo.keyCode === WinJS.Utilities.Key.enter ||
        eventInfo.keyCode === WinJS.Utilities.Key.space)))) {
        eventInfo.preventDefault();
        if (link.href.indexOf("ms-appx") > -1) {
            WinJS.Navigation.navigate(link.href);
        }
        else if (link.href.indexOf("http") > -1) {
            // Create a Uri object from a URI string 
            var uri = new Windows.Foundation.Uri(link.href);
            var options = new Windows.System.LauncherOptions();
            // Launch the URI with a warning prompt
            options.treatAsUntrusted = true;
            // Launch the URI
            Windows.System.Launcher.launchUriAsync(uri, options).then(
                function (success) {
                    if (success) {
                        // URI launched
                    } else {
                        // URI launch failed
                    }
                });
        }
    }
}

Remarks

Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Methods

FindAppUriHandlersAsync(Uri) FindAppUriHandlersAsync(Uri) FindAppUriHandlersAsync(Uri) FindAppUriHandlersAsync(Uri) FindAppUriHandlersAsync(Uri)

Enumerate the Uniform Resource Identifiers (URI) handlers on the device.

FindFileHandlersAsync(String) FindFileHandlersAsync(String) FindFileHandlersAsync(String) FindFileHandlersAsync(String) FindFileHandlersAsync(String)

Enumerate the file handlers on the device.

FindUriSchemeHandlersAsync(String) FindUriSchemeHandlersAsync(String) FindUriSchemeHandlersAsync(String) FindUriSchemeHandlersAsync(String) FindUriSchemeHandlersAsync(String)

Enumerate the scheme handlers on the device.

FindUriSchemeHandlersAsync(String, LaunchQuerySupportType) FindUriSchemeHandlersAsync(String, LaunchQuerySupportType) FindUriSchemeHandlersAsync(String, LaunchQuerySupportType) FindUriSchemeHandlersAsync(String, LaunchQuerySupportType) FindUriSchemeHandlersAsync(String, LaunchQuerySupportType)

Enumerate the scheme handlers on the device.

LaunchFileAsync(IStorageFile) LaunchFileAsync(IStorageFile) LaunchFileAsync(IStorageFile) LaunchFileAsync(IStorageFile) LaunchFileAsync(IStorageFile)

Starts the default app associated with the specified file.

LaunchFileAsync(IStorageFile, LauncherOptions) LaunchFileAsync(IStorageFile, LauncherOptions) LaunchFileAsync(IStorageFile, LauncherOptions) LaunchFileAsync(IStorageFile, LauncherOptions) LaunchFileAsync(IStorageFile, LauncherOptions)

Starts the default app associated with the specified file, using the specified options.

LaunchFolderAsync(IStorageFolder) LaunchFolderAsync(IStorageFolder) LaunchFolderAsync(IStorageFolder) LaunchFolderAsync(IStorageFolder) LaunchFolderAsync(IStorageFolder)

Launches File Explorer and displays the contents of the specified folder.

LaunchFolderAsync(IStorageFolder, FolderLauncherOptions) LaunchFolderAsync(IStorageFolder, FolderLauncherOptions) LaunchFolderAsync(IStorageFolder, FolderLauncherOptions) LaunchFolderAsync(IStorageFolder, FolderLauncherOptions) LaunchFolderAsync(IStorageFolder, FolderLauncherOptions)

Launches File Explorer with the specified options and displays the contents of the specified folder.

LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri)

Starts the default app associated with the URI scheme name for the specified URI.

LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions)

Starts the default app associated with the URI scheme name or the one specified by the ContentType for the specified URI, using the specified options.

LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet)

Starts the default app associated with the URI scheme name for the specified URI, using the specified options and input data.

LaunchUriForResultsAsync(Uri, LauncherOptions) LaunchUriForResultsAsync(Uri, LauncherOptions) LaunchUriForResultsAsync(Uri, LauncherOptions) LaunchUriForResultsAsync(Uri, LauncherOptions) LaunchUriForResultsAsync(Uri, LauncherOptions)

Asynchronously starts the default app associated with the URI scheme name for the specified URI, using the specified options.

LaunchUriForResultsAsync(Uri, LauncherOptions, ValueSet) LaunchUriForResultsAsync(Uri, LauncherOptions, ValueSet) LaunchUriForResultsAsync(Uri, LauncherOptions, ValueSet) LaunchUriForResultsAsync(Uri, LauncherOptions, ValueSet) LaunchUriForResultsAsync(Uri, LauncherOptions, ValueSet)

Asynchronously starts the default app associated with the URI scheme name for the specified URI, using the specified options and input data.

LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions)

Asynchronously starts the default app associated with the URI scheme name for the specified URI using the specified options, and provides a specific User as context.

LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForResultsForUserAsync(User, Uri, LauncherOptions, ValueSet)

Asynchronously starts the default app associated with the URI scheme name for the specified URI using the specified options and input data, and provides a specific User as context.

LaunchUriForUserAsync(User, Uri) LaunchUriForUserAsync(User, Uri) LaunchUriForUserAsync(User, Uri) LaunchUriForUserAsync(User, Uri) LaunchUriForUserAsync(User, Uri)

Starts the default multi-user app associated with the URI scheme name for the specified URI and provides a specific User as context.

LaunchUriForUserAsync(User, Uri, LauncherOptions) LaunchUriForUserAsync(User, Uri, LauncherOptions) LaunchUriForUserAsync(User, Uri, LauncherOptions) LaunchUriForUserAsync(User, Uri, LauncherOptions) LaunchUriForUserAsync(User, Uri, LauncherOptions)

Starts the default multi-user app associated with the URI scheme name for the specified URI using the specified options, and provides a specific User as context.

LaunchUriForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForUserAsync(User, Uri, LauncherOptions, ValueSet) LaunchUriForUserAsync(User, Uri, LauncherOptions, ValueSet)

Starts the default multi-user app associated with the URI scheme name for the specified URI, using the specified options and input data, and provides a specific User as context.

QueryAppUriSupportAsync(Uri) QueryAppUriSupportAsync(Uri) QueryAppUriSupportAsync(Uri) QueryAppUriSupportAsync(Uri) QueryAppUriSupportAsync(Uri)

Asynchronously query whether there is an app that can handle the specified URI.

QueryAppUriSupportAsync(Uri, String) QueryAppUriSupportAsync(Uri, String) QueryAppUriSupportAsync(Uri, String) QueryAppUriSupportAsync(Uri, String) QueryAppUriSupportAsync(Uri, String)

Asynchronously query whether the specified app can handle the specified URI.

QueryFileSupportAsync(StorageFile) QueryFileSupportAsync(StorageFile) QueryFileSupportAsync(StorageFile) QueryFileSupportAsync(StorageFile) QueryFileSupportAsync(StorageFile)

Asynchronously query whether an app can be activated for the specified file.

QueryFileSupportAsync(StorageFile, String) QueryFileSupportAsync(StorageFile, String) QueryFileSupportAsync(StorageFile, String) QueryFileSupportAsync(StorageFile, String) QueryFileSupportAsync(StorageFile, String)

Asynchronously query whether an app with the specified package name can be activated for the specified file.

QueryUriSupportAsync(Uri, LaunchQuerySupportType) QueryUriSupportAsync(Uri, LaunchQuerySupportType) QueryUriSupportAsync(Uri, LaunchQuerySupportType) QueryUriSupportAsync(Uri, LaunchQuerySupportType) QueryUriSupportAsync(Uri, LaunchQuerySupportType)

Asynchronously query whether an app can be activated for the specified URI and launch type.

QueryUriSupportAsync(Uri, LaunchQuerySupportType, String) QueryUriSupportAsync(Uri, LaunchQuerySupportType, String) QueryUriSupportAsync(Uri, LaunchQuerySupportType, String) QueryUriSupportAsync(Uri, LaunchQuerySupportType, String) QueryUriSupportAsync(Uri, LaunchQuerySupportType, String)

Asynchronously query whether an app can be activated for the specified URI, launch type, and package name.

See Also