CommandLineActivatedEventArgs 类

定义

提供从命令行激活应用时的信息,例如命令行参数。

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
继承
Object Platform::Object IInspectable CommandLineActivatedEventArgs
属性
实现

Windows 要求

设备系列
Windows 10 Fall Creators Update (在 10.0.16299.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v5.0 中引入)

示例

下面是处理命令行启动的示例:

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

注解

可从“开始”屏幕激活 UWP 应用 | 在 Windows 中,从 PowerShell 中的命令行、DOS 命令提示符或从另一个调用 CreateProcess () 的 Win32 进程运行 。

若要从命令行激活,应用必须在其清单中注册“AppExecutionAlias”扩展类别。

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

在清单中注册后,可以从命令行激活应用。 激活应用后,可以使用事件信息来标识呼叫激活,并提取有助于完成用户呼叫的参数。

属性

Kind

获取启动应用的激活类型。

Operation

获取有关应用激活的信息,例如提供了哪些参数和当前目录路径。

PreviousExecutionState

获取激活前的应用的执行状态。

SplashScreen

获取有关从初始屏幕过渡到激活的应用的信息。

User

获取为其激活应用的用户。

适用于