CommandLineActivatedEventArgs CommandLineActivatedEventArgs CommandLineActivatedEventArgs CommandLineActivatedEventArgs CommandLineActivatedEventArgs Class

Definition

Provides information, such as the command-line arguments, when an app is activated from the command line.

public : sealed class CommandLineActivatedEventArgs : IActivatedEventArgs, IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
struct winrt::Windows::ApplicationModel::Activation::CommandLineActivatedEventArgs : IActivatedEventArgs, IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
public sealed class CommandLineActivatedEventArgs : IActivatedEventArgs, IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
Public NotInheritable Class CommandLineActivatedEventArgs Implements IActivatedEventArgs, IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Examples

Here is an example of handling a command-line launch:

protected override void OnActivated(IActivatedEventArgs args)
{
    string activationArgString = string.Empty;
    string activationPath = string.Empty;
    string cmdLineString = string.Empty;

    // Existing behavior to differentiate different activation kinds,
    // and to extract any argument payload.
    switch (args.Kind)
    {
        case ActivationKind.Launch:
            var launchArgs = args as LaunchActivatedEventArgs;
            activationArgString = launchArgs.Arguments;
            break;

        // A new ActivationKind for console activation of a windowed app.
        case ActivationKind.CommandLineLaunch:
            CommandLineActivatedEventArgs cmdLineArgs = args as CommandLineActivatedEventArgs;
            CommandLineActivationOperation operation = cmdLineArgs.Operation;
            cmdLineString = operation.Arguments;
            activationPath = operation.CurrentDirectoryPath;
            break;
    }

    // Parse the trusted activation arguments.
    ParseTrustedArgs(activationArgString);

    // Parse the untrusted command-line arguments.
    ParseUntrustedArgs(activationPath, cmdLineString);

    // Since we did not take a deferral, the calling app gets the result
    // as soon as this method returns. Since we did not set an exit code,
    // the calling app gets a default exit code as the result.
}    

Remarks

A UWP app may be activated from Start|Run in Windows, from the command line in PowerShell, the DOS command prompt, or from another Win32 process that calls CreateProcess().

To be activated from the command line, your app must register for the "AppExecutionAlias" extension category in its manifest.

<uap5:Extension Category="windows.appExecutionAlias" Executable="FruitSalad.exe" EntryPoint="Windows.FruitSalad.Bananas.App">
    <uap5:AppExecutionAlias >
        <uap5:ExecutionAlias Alias="Fs.exe" />
    </uap5:AppExecutionAlias>
</uap5:Extension>

After you register in your manifest, your app can be activated from the command line. When your app is activated, you can use the event information to identify the call activation and extract the parameters that help you complete the call for the user.

Properties

Kind Kind Kind Kind Kind

Gets the type of activation that launched the app.

Operation Operation Operation Operation Operation

Gets info about the activation of the app such as what arguments were provided and the current directory path.

PreviousExecutionState PreviousExecutionState PreviousExecutionState PreviousExecutionState PreviousExecutionState

Gets the execution state of the app before it was activated.

SplashScreen SplashScreen SplashScreen SplashScreen SplashScreen

Gets info about the transition from the splash screen to the activated app.

User User User User User

Gets the user that the app was activated for.