AppListEntry.LaunchForUserAsync(User) Method

Definition

Launch the app associated with this AppListEntry within the context of a specified user.

public:
 virtual IAsyncOperation<bool> ^ LaunchForUserAsync(User ^ user) = LaunchForUserAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<bool> LaunchForUserAsync(User const& user);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<bool> LaunchForUserAsync(User user);
function launchForUserAsync(user)
Public Function LaunchForUserAsync (user As User) As IAsyncOperation(Of Boolean)

Parameters

user
User

The user context that the app should be launched under.

Returns

Returns true if the launch succeeds; otherwise, false.

Attributes

Windows requirements

Device family
Windows 10, version 1803 (introduced in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v6.0)

Examples

public async void LaunchButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
    // The active User is retrieved from the initial activation args and validated against list of active users
    User user = this.GetAppActiveUser();
    PackageManager pm = new PackageManager();
    // The App Family Name is stored as part of the Product Display Page
    Package p = pm.FindPackage(this.GetFocusedAppFamilyName());
    IReadOnlyList<AppListEntry> entries = await p.GetAppListEntriesAsync();

    //This assumes the first app in the package should be launched, if there is one in the package
    if (entries.Count > 0)
    {
        await entries[0].LaunchForUserAsync(user);
    }
}

Remarks

This is a Multi-User-Aware (MUA) API and can only be used by apps that declare themselves to be MUA, and only on devices that support MUA apps. The app is launched in the same way as if the specified user clicked on the entry in the app list. The user is passed to the launched app via the event args. Passing null for user will result in an exception.

MUA apps launch with the a default user context. The user value, which is passed to the activated application via the event arguments, indicates who the app is activating on behalf of. A Single-User-Aware app will launch in the context of the user value that is passed into this API.

Applies to

See also