Share via


Launcher Class

Definition

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

public ref class Launcher abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class Launcher final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Launcher final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public static class Launcher
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class Launcher
Public Class Launcher
Inheritance
Object Platform::Object IInspectable Launcher
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

Launch a file contained in the app package

See the code example in the LaunchFileAsync(IStorageFile) topic.

Launch a URI

See the code example in the LaunchUriAsync(Uri) topic.

Launch with a warning dialog

This example calls 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 a Windows app using JavaScript, call preventDefault in your event handler if the treatAsUntrusted property is set and you are using an anchor 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).

Version history

Windows version SDK version Value added
1607 14393 FindAppUriHandlersAsync
1607 14393 LaunchUriForResultsForUserAsync(User,Uri,LauncherOptions)
1607 14393 LaunchUriForResultsForUserAsync(User,Uri,LauncherOptions,ValueSet)
1607 14393 LaunchUriForUserAsync(User,Uri)
1607 14393 LaunchUriForUserAsync(User,Uri,LauncherOptions)
1607 14393 LaunchUriForUserAsync(User,Uri,LauncherOptions,ValueSet)
1607 14393 QueryAppUriSupportAsync(Uri)
1607 14393 QueryAppUriSupportAsync(Uri,String)
1809 17763 LaunchFolderPathAsync(String)
1809 17763 LaunchFolderPathAsync(String,FolderLauncherOptions)
1809 17763 LaunchFolderPathForUserAsync(User,String)
1809 17763 LaunchFolderPathForUserAsync(User,String,FolderLauncherOptions)

Methods

FindAppUriHandlersAsync(Uri)

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

FindFileHandlersAsync(String)

Enumerate the file handlers on the device.

FindUriSchemeHandlersAsync(String, LaunchQuerySupportType)

Enumerate the scheme handlers on the device.

FindUriSchemeHandlersAsync(String)

Enumerate the scheme handlers on the device.

LaunchFileAsync(IStorageFile, LauncherOptions)

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

LaunchFileAsync(IStorageFile)

Starts the default app associated with the specified file.

LaunchFolderAsync(IStorageFolder, FolderLauncherOptions)

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

LaunchFolderAsync(IStorageFolder)

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

LaunchFolderPathAsync(String, FolderLauncherOptions)

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

LaunchFolderPathAsync(String)

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

LaunchFolderPathForUserAsync(User, String, FolderLauncherOptions)

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

LaunchFolderPathForUserAsync(User, String)

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

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.

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)

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

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.

LaunchUriForResultsAsync(Uri, LauncherOptions)

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

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.

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.

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.

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)

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

QueryAppUriSupportAsync(Uri, String)

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

QueryAppUriSupportAsync(Uri)

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

QueryFileSupportAsync(StorageFile, String)

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

QueryFileSupportAsync(StorageFile)

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

QueryUriSupportAsync(Uri, LaunchQuerySupportType, String)

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

QueryUriSupportAsync(Uri, LaunchQuerySupportType)

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

Applies to

See also