CommandLineActivatedEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供從命令列啟動應用程式時的資訊,例如命令列引數。
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
- 繼承
- 屬性
- 實作
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 app 可以從 \[開始\] 啟動|從 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 |
取得啟動應用程式的使用者。 |