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 アプリがアクティブ化される場合がある | PowerShell のコマンド ライン、DOS コマンド プロンプト、または CreateProcess() を呼び出す別の Win32 プロセスから Windows で実行します。

コマンド ラインからアクティブ化するには、アプリをマニフェストの "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

アプリがアクティブ化されたユーザーを取得します。

適用対象