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

Gets the type of activation that launched the app.

public : ActivationKind Kind { get; }
public ActivationKind Kind { get; }
Public ReadOnly Property Kind As ActivationKind
var activationKind = commandLineActivatedEventArgs.kind;

Remarks

The expected value is ActivationKind.CommandLineLaunch.

Operation Operation Operation Operation

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

public : CommandLineActivationOperation Operation { get; }
public CommandLineActivationOperation Operation { get; }
Public ReadOnly Property Operation As CommandLineActivationOperation
var commandLineActivationOperation = commandLineActivatedEventArgs.operation;

Remarks

The app supplies the exit code which is passed back to the caller.

See Also

PreviousExecutionState PreviousExecutionState PreviousExecutionState PreviousExecutionState

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

public : ApplicationExecutionState PreviousExecutionState { get; }
public ApplicationExecutionState PreviousExecutionState { get; }
Public ReadOnly Property PreviousExecutionState As ApplicationExecutionState
var applicationExecutionState = commandLineActivatedEventArgs.previousExecutionState;

SplashScreen SplashScreen SplashScreen SplashScreen

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

public : SplashScreen SplashScreen { get; }
public SplashScreen SplashScreen { get; }
Public ReadOnly Property SplashScreen As SplashScreen
var splashScreen = commandLineActivatedEventArgs.splashScreen;
Value
SplashScreen SplashScreen SplashScreen SplashScreen

The splash screen transition info.

User User User User

Gets the user that the app was activated for.

public : User User { get; }
public User User { get; }
Public ReadOnly Property User As User
var user = commandLineActivatedEventArgs.user;
Value
User User User User

The user that the app was activated for.