Launcher Launcher Launcher Launcher Class

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

Syntax

Declaration

public static class Launcherpublic static class LauncherPublic Static Class Launcher

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).

Examples

Launch a file contained in the app packageThis example uses LaunchFileAsync(Windows.Storage.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(Windows.Foundation.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(Windows.Foundation.Uri,Windows.System.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
                    }
                });
        }
    }
}

Methods summary

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

Enumerate the file handlers on the device.

Enumerate the scheme handlers on the device.

Enumerate the scheme handlers on the device.

Starts the default app associated with the specified file.

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

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

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

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

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.

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

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

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

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.

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.

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

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.

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.

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

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

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

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

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

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

Methods

  • FindAppUriHandlersAsync(Windows.Foundation.Uri)
    FindAppUriHandlersAsync(Windows.Foundation.Uri)
    FindAppUriHandlersAsync(Windows.Foundation.Uri)
    FindAppUriHandlersAsync(Windows.Foundation.Uri)

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

    public static IAsyncOperation<AppInfo>> FindAppUriHandlersAsync(Windows.Foundation.Uri uri)public static IAsyncOperation<AppInfo>> FindAppUriHandlersAsync(Windows.Foundation.Uri uri)Public Static Function FindAppUriHandlersAsync(uri As Windows.Foundation.Uri) As IAsyncOperation( Of AppInfo )

    Parameters

    • uri

      The Uri that you want to find handlers for.

    Returns

    • A list of AppInfo objects representing each application that handles the specified http(s) URI.

    Remarks

    This API may also be called from Windows desktop application but does not return Windows desktop application.

  • FindFileHandlersAsync(System.String)
    FindFileHandlersAsync(System.String)
    FindFileHandlersAsync(System.String)
    FindFileHandlersAsync(System.String)

    Enumerate the file handlers on the device.

    public static IAsyncOperation<AppInfo>> FindFileHandlersAsync(System.String extension)public static IAsyncOperation<AppInfo>> FindFileHandlersAsync(System.String extension)Public Static Function FindFileHandlersAsync(extension As System.String) As IAsyncOperation( Of AppInfo )

    Parameters

    • extension
      System.String
      System.String
      System.String
      System.String

      The file extension that you want to find handlers for. For example, ".bat". Include the leading period '.'.

    Returns

    • A list of AppInfo s for each application that handles the specified file extension.

    Remarks

    This API may also be called from Windows desktop application but does not return Windows desktop application.

  • FindUriSchemeHandlersAsync(System.String)
    FindUriSchemeHandlersAsync(System.String)
    FindUriSchemeHandlersAsync(System.String)
    FindUriSchemeHandlersAsync(System.String)

    Enumerate the scheme handlers on the device.

    public static IAsyncOperation<AppInfo>> FindUriSchemeHandlersAsync(System.String scheme)public static IAsyncOperation<AppInfo>> FindUriSchemeHandlersAsync(System.String scheme)Public Static Function FindUriSchemeHandlersAsync(scheme As System.String) As IAsyncOperation( Of AppInfo )

    Parameters

    • scheme
      System.String
      System.String
      System.String
      System.String

      The scheme name that you find to find handlers for. For example, "ms-lens".

    Returns

    • A list of AppInfo s for each application that handles the specified scheme.

    Remarks

    This API may also be called from Windows desktop application but does not return Windows desktop application.

  • FindUriSchemeHandlersAsync(System.String,Windows.System.LaunchQuerySupportType)
    FindUriSchemeHandlersAsync(System.String,Windows.System.LaunchQuerySupportType)
    FindUriSchemeHandlersAsync(System.String,Windows.System.LaunchQuerySupportType)
    FindUriSchemeHandlersAsync(System.String,Windows.System.LaunchQuerySupportType)

    Enumerate the scheme handlers on the device.

    public static IAsyncOperation<AppInfo>> FindUriSchemeHandlersAsync(System.String scheme,Windows.System.LaunchQuerySupportType launchQuerySupportType)public static IAsyncOperation<AppInfo>> FindUriSchemeHandlersAsync(System.String scheme,Windows.System.LaunchQuerySupportType launchQuerySupportType)Public Static Function FindUriSchemeHandlersAsync(scheme As System.String,launchQuerySupportType As Windows.System.LaunchQuerySupportType) As IAsyncOperation( Of AppInfo )

    Parameters

    Returns

    • A list of AppInfo s for each application that handles the specified scheme.

    Remarks

    This API may also be called from Windows desktop application but does not return Windows desktop application.

  • LaunchFileAsync(Windows.Storage.IStorageFile)
    LaunchFileAsync(Windows.Storage.IStorageFile)
    LaunchFileAsync(Windows.Storage.IStorageFile)
    LaunchFileAsync(Windows.Storage.IStorageFile)

    Starts the default app associated with the specified file.

    public static IAsyncOperation<bool> LaunchFileAsync(Windows.Storage.IStorageFile file)public static IAsyncOperation<bool> LaunchFileAsync(Windows.Storage.IStorageFile file)Public Static Function LaunchFileAsync(file As Windows.Storage.IStorageFile) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • The launch operation.

    Remarks

    The calling app must be visible to the user when the API is invoked.

    This API must be called from an ASTA thread (also known as a UI thread).

    This API also imposes several restrictions on what types of files it can launch. Many file types that contain executable code, for example .exe, .msi, and .js files, are blocked from launching. This restriction protects users from potentially malicious files that could modify the system.

    When the launch fails for any of the above reasons, the API succeeds and returns FALSE from its asynchronous operation. Since it has no ability to query whether the above restrictions apply to the current launch, the calling app should not assume that the launch succeeded, and should provide fallback mechanism in case it failed. A possible solution would be to ask the user to save the file and direct the user to open it in the desktop.

    To enable the user to choose an app instead of launching the default app, set the DisplayApplicationPicker property.

    To display a warning that the file is potentially unsafe, set the TreatAsUntrusted property.

    The file is passed to the associated app. If the associated app is a desktop app, the file is passed using shell execution mechanisms.

    Examples

    This example uses LaunchFileAsync(Windows.Storage.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 = wait 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
          }
       });
    }
    
  • LaunchFileAsync(Windows.Storage.IStorageFile,Windows.System.LauncherOptions)
    LaunchFileAsync(Windows.Storage.IStorageFile,Windows.System.LauncherOptions)
    LaunchFileAsync(Windows.Storage.IStorageFile,Windows.System.LauncherOptions)
    LaunchFileAsync(Windows.Storage.IStorageFile,Windows.System.LauncherOptions)

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

    public static IAsyncOperation<bool> LaunchFileAsync(Windows.Storage.IStorageFile file,Windows.System.LauncherOptions options)public static IAsyncOperation<bool> LaunchFileAsync(Windows.Storage.IStorageFile file,Windows.System.LauncherOptions options)Public Static Function LaunchFileAsync(file As Windows.Storage.IStorageFile,options As Windows.System.LauncherOptions) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • The launch operation.

    Remarks

    The calling app must be visible to the user when the API is invoked.

    This API must be called from within an ASTA thread (also known as a UI thread).

    This API also imposes several restrictions on what types of files it can launch. Many file types that contain executable code, for example .exe, .msi, and .js files, are blocked from launching. This restriction protects users from potentially malicious files that could modify the system.

    When the launch fails for any of the above reasons, the API succeeds and returns FALSE from its asynchronous operation. Since it has no ability to query whether the above restrictions apply to the current launch, the calling app should not assume that the launch succeeded, and should provide fallback mechanism in case it failed. A possible solution would be to ask the user to save the file and direct the user to open it in the desktop.

    To enable the user to choose an app instead of launching the default app, set the DisplayApplicationPicker property.

    To display a warning that the file is potentially unsafe, set the TreatAsUntrusted property.

    The file is passed to the associated app. If the associated app is a desktop app, the file is passed using shell execution mechanisms.

    Examples

    Call the LaunchFileAsync(Windows.Storage.IStorageFile,Windows.System.LauncherOptions) method with DisplayApplicationPicker set to true to launch the app that the user selects for the file from the Open With dialog box.

    
    // 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) {
        // Set the show picker option
        var options = new Windows.System.LauncherOptions();
        options.displayApplicationPicker = true;
    
        // Launch the retrieved file using the selected app
        Windows.System.Launcher.launchFileAsync(file, options).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)
       {
          // 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
          }
       }
       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
          ' Set the option to show the picker
          Dim options = Windows.System.LauncherOptions()
          options.DisplayApplicationPicker = True
    
          ' Launch the retrieved file
          Dim success = await Windows.System.Launcher.LaunchFileAsync(file, options)
    
          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)
          {
             // Set the option to show the picker
             auto launchOptions = ref new Windows::System::LauncherOptions();
             launchOptions->DisplayApplicationPicker = true;
    
             // Launch the retrieved file
             concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file, launchOptions));
             launchFileOperation.then([](bool success)
             {
                if (success)
                {
                   // File launched
                }
                else
                {
                   // File launch failed
                }
             });
          }
          else
          {
             // Could not find file
          }
       });
    }
    
  • LaunchFolderAsync(Windows.Storage.IStorageFolder)
    LaunchFolderAsync(Windows.Storage.IStorageFolder)
    LaunchFolderAsync(Windows.Storage.IStorageFolder)
    LaunchFolderAsync(Windows.Storage.IStorageFolder)

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

    public static IAsyncOperation<bool> LaunchFolderAsync(Windows.Storage.IStorageFolder folder)public static IAsyncOperation<bool> LaunchFolderAsync(Windows.Storage.IStorageFolder folder)Public Static Function LaunchFolderAsync(folder As Windows.Storage.IStorageFolder) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • The result of the operation.

    Remarks

    This API must be called from within an ASTA thread (also known as a UI thread).

  • LaunchFolderAsync(Windows.Storage.IStorageFolder,Windows.System.FolderLauncherOptions)
    LaunchFolderAsync(Windows.Storage.IStorageFolder,Windows.System.FolderLauncherOptions)
    LaunchFolderAsync(Windows.Storage.IStorageFolder,Windows.System.FolderLauncherOptions)
    LaunchFolderAsync(Windows.Storage.IStorageFolder,Windows.System.FolderLauncherOptions)

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

    public static IAsyncOperation<bool> LaunchFolderAsync(Windows.Storage.IStorageFolder folder,Windows.System.FolderLauncherOptions options)public static IAsyncOperation<bool> LaunchFolderAsync(Windows.Storage.IStorageFolder folder,Windows.System.FolderLauncherOptions options)Public Static Function LaunchFolderAsync(folder As Windows.Storage.IStorageFolder,options As Windows.System.FolderLauncherOptions) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • The result of the operation.

    Remarks

    This API must be called from within an ASTA thread (also known as a UI thread).

  • LaunchUriAsync(Windows.Foundation.Uri)
    LaunchUriAsync(Windows.Foundation.Uri)
    LaunchUriAsync(Windows.Foundation.Uri)
    LaunchUriAsync(Windows.Foundation.Uri)

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

    public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri)public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri)Public Static Function LaunchUriAsync(uri As Windows.Foundation.Uri) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • Returns true if the default app for the URI scheme was launched; false otherwise.

    Remarks

    Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

    This API may also be called from a Windows desktop application.

    This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

    The calling app must be visible to the user when the API is invoked.

    You must specify the privateNetworkClientServer capability in the manifest in order to launch intranet URIs, for example a file:/// URI pointing to a network location.

    You cannot use this method to launch a URI in the local zone. For example, apps cannot use the file:/// protocol to access files on the local computer. Instead, you must use the Windows.Storage to access files.

    When the launch fails for any of the above reasons, the API will succeed and return FALSE from its asynchronous operation.

    To enable the user to choose an app instead of launching the default app, set the DisplayApplicationPicker property.

    To display a warning that the URI is potentially unsafe, set the TreatAsUntrusted property.

    The URI is passed to the associated app. If the associated app is a desktop app, the URI is passed using shell execution mechanisms.

    Examples

    This example uses LaunchUriAsync(Windows.Foundation.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
          }
       });
    }
    
  • LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.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.

    public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)Public Static Function LaunchUriAsync(uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • Returns true if the default app for the URI scheme was launched; false otherwise.

    Remarks

    Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

    This API may also be called from a Windows desktop application.

    This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

    The calling app must be visible to the user when this API is invoked.

    Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as a UI thread).

    You must specify the privateNetworkClientServer capability in the manifest in order to launch intranet URIs, for example a file:/// URI pointing to a network location.

    You cannot use this method to launch a URI in the local zone. For example, apps cannot use the file:/// protocol to access files on the local computer. Instead, you must use the Windows.Storage to access files.

    The content type is used to compute a file extension, from the extension the default app is chosen. For example a content type value of ""application/vnd.ms-word.document.12"" is mapped to ".docx" and then the default application for ".docx" is launched. For example:

    
    // this specifies the file type, which is used to bind to Word. 
    launcherOptions.ContentType = "application/vnd.ms-word.document.12"; 
    // and then this launches the file using the application
    Launcher.LaunchUriAsync("http://www.cloud.com/file.docx", options);
    

    When the launch fails for any of the above reasons, the API will succeed and return FALSE from its asynchronous operation.

    To enable the user to choose an app instead of launching the default app, set the DisplayApplicationPicker property.

    To display a warning that the URI is potentially unsafe, set the TreatAsUntrusted property.

    The URI is passed to the associated app. If the associated app is a desktop app, the URI is passed using shell execution mechanisms.

    Examples

    This sample uses LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions) to launch a URI with a warning. The TreatAsUntrusted property indicates 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.

    
    // 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 with a warning prompt
    var options = new Windows.System.LauncherOptions();
    options.treatAsUntrusted = true;
    
    Windows.System.Launcher.launchUriAsync(uri, options).then(
       function (success) {
          if (success) {
             // URI launched
          } else {
             // URI launch failed
          }
       });
    
    // The URI to launch
    string uriToLaunch = @"http://www.bing.com";
    var uri = new Uri(uriToLaunch);
    
    async void DefaultLaunch()
    {
       // Set the option to show a warning
       var options = new Windows.System.LauncherOptions();
       options.TreatAsUntrusted = true;
    
       // Launch the URI with a warning prompt
       var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
    
       if (success)
       {
          // URI launched
       }
       else
       {
          // URI launch failed
       }
    }
    
    ' The URI to launch
    Dim uri As New Uri("http://www.bing.com")
    
    async Sub DefaultLaunch()
    
       ' Set the option to show a warning
       Dim options = Windows.System.LauncherOptions()
       options.TreatAsUntrusted = True
    
       ' Launch the URI with a warning prompt
       Dim success = await Windows.System.Launcher.LaunchUriAsync(uri, options)
    
       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()
    {
       // Set the option to show a warning
       auto launchOptions = ref new Windows::System::LauncherOptions();
       launchOptions->TreatAsUntrusted = true;
    
       // Launch the URI with a warning prompt
       concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri, launchOptions));
       launchUriOperation.then([](bool success)
       {
          if (success)
          {
             // URI launched
          }
          else
          {
             // URI launch failed
          }
       });
    }
    
  • LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)

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

    public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)public static IAsyncOperation<bool> LaunchUriAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)Public Static Function LaunchUriAsync(uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions,inputData As Windows.Foundation.Collections.ValueSet) As IAsyncOperation( Of bool )

    Parameters

    Returns

    • Returns true if the default app for the URI scheme was launched; false otherwise.

    Remarks

    Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

    This API may also be called from a Windows desktop application.

    This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

  • LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions)

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

    public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)Public Static Function LaunchUriForResultsAsync(uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions) As IAsyncOperation( Of LaunchUriResult )

    Parameters

    Returns

    • When this method completes, it returns the results of the launch.

    Remarks

    Launching an app for results allows you to launch an app from another app and exchange data between the two.

    This API must be called from within an ASTA thread (also known as a UI thread).

  • LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsAsync(Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)

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

    public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsAsync(Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)Public Static Function LaunchUriForResultsAsync(uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions,inputData As Windows.Foundation.Collections.ValueSet) As IAsyncOperation( Of LaunchUriResult )

    Parameters

    Returns

    • When this method completes, it returns the results of the launch.

    Remarks

    Launching an app for results allows you to launch an app from another app and exchange data between the two.

    This API must be called from within an ASTA thread (also known as a UI thread).

  • LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.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.

    public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)Public Static Function LaunchUriForResultsForUserAsync(user As Windows.System.User,uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions) As IAsyncOperation( Of LaunchUriResult )

    Parameters

    Returns

    • When this method completes, it returns the results of the launch.

  • LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForResultsForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.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.

    public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)public static IAsyncOperation<LaunchUriResult> LaunchUriForResultsForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)Public Static Function LaunchUriForResultsForUserAsync(user As Windows.System.User,uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions,inputData As Windows.Foundation.Collections.ValueSet) As IAsyncOperation( Of LaunchUriResult )

    Parameters

    Returns

    • When this method completes, it returns the results of the launch.

  • LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri)

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

    public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri)public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri)Public Static Function LaunchUriForUserAsync(user As Windows.System.User,uri As Windows.Foundation.Uri) As IAsyncOperation( Of LaunchUriStatus )

    Parameters

    Returns

    • The status of the launch attempt.

  • LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.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.

    public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options)Public Static Function LaunchUriForUserAsync(user As Windows.System.User,uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions) As IAsyncOperation( Of LaunchUriStatus )

    Parameters

    Returns

    • The status of the launch attempt.

  • LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.ValueSet)
    LaunchUriForUserAsync(Windows.System.User,Windows.Foundation.Uri,Windows.System.LauncherOptions,Windows.Foundation.Collections.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.

    public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)public static IAsyncOperation<LaunchUriStatus> LaunchUriForUserAsync(Windows.System.User user,Windows.Foundation.Uri uri,Windows.System.LauncherOptions options,Windows.Foundation.Collections.ValueSet inputData)Public Static Function LaunchUriForUserAsync(user As Windows.System.User,uri As Windows.Foundation.Uri,options As Windows.System.LauncherOptions,inputData As Windows.Foundation.Collections.ValueSet) As IAsyncOperation( Of LaunchUriStatus )

    Parameters

    Returns

    • The status of the launch attempt.

  • QueryAppUriSupportAsync(Windows.Foundation.Uri)
    QueryAppUriSupportAsync(Windows.Foundation.Uri)
    QueryAppUriSupportAsync(Windows.Foundation.Uri)
    QueryAppUriSupportAsync(Windows.Foundation.Uri)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryAppUriSupportAsync(Windows.Foundation.Uri uri)public static IAsyncOperation<LaunchQuerySupportStatus> QueryAppUriSupportAsync(Windows.Foundation.Uri uri)Public Static Function QueryAppUriSupportAsync(uri As Windows.Foundation.Uri) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    Returns

    • A value that indicates whether an application is available to handle the URI.

    Remarks

    Windows desktop application are not considered.

  • QueryAppUriSupportAsync(Windows.Foundation.Uri,System.String)
    QueryAppUriSupportAsync(Windows.Foundation.Uri,System.String)
    QueryAppUriSupportAsync(Windows.Foundation.Uri,System.String)
    QueryAppUriSupportAsync(Windows.Foundation.Uri,System.String)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryAppUriSupportAsync(Windows.Foundation.Uri uri,System.String packageFamilyName)public static IAsyncOperation<LaunchQuerySupportStatus> QueryAppUriSupportAsync(Windows.Foundation.Uri uri,System.String packageFamilyName)Public Static Function QueryAppUriSupportAsync(uri As Windows.Foundation.Uri,packageFamilyName As System.String) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    • uri

      The URI of the website.

    • packageFamilyName
      System.String
      System.String
      System.String
      System.String

      Specifies a specific package that will be used to launch this URI.

    Returns

    • A value that indicates whether the application is available to launch the URI.

    Remarks

    Windows desktop application are not considered.

  • QueryFileSupportAsync(Windows.Storage.StorageFile)
    QueryFileSupportAsync(Windows.Storage.StorageFile)
    QueryFileSupportAsync(Windows.Storage.StorageFile)
    QueryFileSupportAsync(Windows.Storage.StorageFile)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryFileSupportAsync(Windows.Storage.StorageFile file)public static IAsyncOperation<LaunchQuerySupportStatus> QueryFileSupportAsync(Windows.Storage.StorageFile file)Public Static Function QueryFileSupportAsync(file As Windows.Storage.StorageFile) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    Returns

    • A value that indicates whether an application can be activated for the file.

    Remarks

    This API may also be called from Windows desktop application.

    Both Windows desktop application and Universal Windows Platform (UWP) app are considered.

  • QueryFileSupportAsync(Windows.Storage.StorageFile,System.String)
    QueryFileSupportAsync(Windows.Storage.StorageFile,System.String)
    QueryFileSupportAsync(Windows.Storage.StorageFile,System.String)
    QueryFileSupportAsync(Windows.Storage.StorageFile,System.String)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryFileSupportAsync(Windows.Storage.StorageFile file,System.String packageFamilyName)public static IAsyncOperation<LaunchQuerySupportStatus> QueryFileSupportAsync(Windows.Storage.StorageFile file,System.String packageFamilyName)Public Static Function QueryFileSupportAsync(file As Windows.Storage.StorageFile,packageFamilyName As System.String) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    Returns

    • A value that indicates whether an application can be activated for the file.

    Remarks

    This API may also be called from Windows desktop application.

    Both Windows desktop application and Universal Windows Platform (UWP) app are considered.

  • QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryUriSupportAsync(Windows.Foundation.Uri uri,Windows.System.LaunchQuerySupportType launchQuerySupportType)public static IAsyncOperation<LaunchQuerySupportStatus> QueryUriSupportAsync(Windows.Foundation.Uri uri,Windows.System.LaunchQuerySupportType launchQuerySupportType)Public Static Function QueryUriSupportAsync(uri As Windows.Foundation.Uri,launchQuerySupportType As Windows.System.LaunchQuerySupportType) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    Returns

    • A value that indicates whether an application is available to launch the URI.

    Remarks

    This API may also be called from Windows desktop application.

    Both Windows desktop application and Universal Windows Platform (UWP) app are considered.

  • QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType,System.String)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType,System.String)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType,System.String)
    QueryUriSupportAsync(Windows.Foundation.Uri,Windows.System.LaunchQuerySupportType,System.String)

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

    public static IAsyncOperation<LaunchQuerySupportStatus> QueryUriSupportAsync(Windows.Foundation.Uri uri,Windows.System.LaunchQuerySupportType launchQuerySupportType,System.String packageFamilyName)public static IAsyncOperation<LaunchQuerySupportStatus> QueryUriSupportAsync(Windows.Foundation.Uri uri,Windows.System.LaunchQuerySupportType launchQuerySupportType,System.String packageFamilyName)Public Static Function QueryUriSupportAsync(uri As Windows.Foundation.Uri,launchQuerySupportType As Windows.System.LaunchQuerySupportType,packageFamilyName As System.String) As IAsyncOperation( Of LaunchQuerySupportStatus )

    Parameters

    Returns

    • A value that indicates whether the application is available to launch the URI.

    Remarks

    This API may also be called from Windows desktop application.

    Both Windows desktop application and Universal Windows Platform (UWP) app are considered.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute

Details

Assembly

Windows.System.dll