Delen via


CommandLineActivatedEventArgs Class

Definition

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

public ref class CommandLineActivatedEventArgs sealed : IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 327680)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CommandLineActivatedEventArgs final : IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 327680)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CommandLineActivatedEventArgs : IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
Public NotInheritable Class CommandLineActivatedEventArgs
Implements IActivatedEventArgsWithUser, ICommandLineActivatedEventArgs
Inheritance
Object Platform::Object IInspectable CommandLineActivatedEventArgs
Attributes
Implements

Windows requirements

Device family
Windows 10 Fall Creators Update (introduced in 10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v5.0)

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

Gets the type of activation that launched the app.

Operation

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

PreviousExecutionState

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

SplashScreen

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

User

Gets the user that the app was activated for.

Applies to