ConsoleApplicationBase.CommandLineArgs プロパティ

定義

現在のアプリケーションのコマンド ライン引数が文字列として格納されたコレクションを取得します。

public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ CommandLineArgs { System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<string> CommandLineArgs { get; }
member this.CommandLineArgs : System.Collections.ObjectModel.ReadOnlyCollection<string>
Public ReadOnly Property CommandLineArgs As ReadOnlyCollection(Of String)

プロパティ値

現在のアプリケーションのコマンド ライン引数が文字列として格納された、StringReadOnlyCollection<T>

この例では、 プロパティを My.Application.CommandLineArgs 使用して、アプリケーションのコマンド ライン引数を調べます。 で /input=始まる引数が見つかった場合は、その引数の残りの部分が表示されます。

Private Sub ParseCommandLineArgs()
    Dim inputArgument As String = "/input="
    Dim inputName As String = ""

    For Each s As String In My.Application.CommandLineArgs
        If s.ToLower.StartsWith(inputArgument) Then
            inputName = s.Remove(0, inputArgument.Length)
        End If
    Next

    If inputName = "" Then
        MsgBox("No input name")
    Else
        MsgBox("Input name: " & inputName)
    End If
End Sub

注釈

プロパティは My.Application.CommandLineArgs 、ClickOnce が配置されていないアプリケーションの現在のアプリケーションのコマンド ライン引数への読み取り専用アクセスを提供します。

単一インスタンス アプリケーションの場合、 プロパティは My.Application.CommandLineArgs 、アプリケーションの最初のインスタンスのコマンド ライン引数を返します。 後続の単一インスタンス アプリケーションの起動試行の引数にアクセスするには、 イベントをStartupNextInstance処理し、 引数の プロパティをCommandLineStartupEventArgs調べる必要があります。

注意

プロパティは My.Application.CommandLineArgs 、コマンド ライン引数のみを返します。 これは、引数に加えてアプリケーション名を CommandLine 返す プロパティの動作とは異なります。

注意

ClickOnce が配置されているアプリケーションでは、 オブジェクトの プロパティをActivationUriMy.Application.Deployment使用してコマンド ライン引数を取得します。 詳細については、「Deployment」を参照してください。

次の表に、 プロパティに関連するタスクの例を My.Application.CommandLineArgs 示します。

終了 解決方法については、
後続の単一インスタンス アプリケーションの起動試行のコマンド ライン引数を確認する StartupNextInstance

プロジェクトの種類別の可用性

プロジェクトの種類 使用可能
Windows アプリケーション はい
クラス ライブラリ いいえ
コンソール アプリケーション はい
Windows コントロール ライブラリ いいえ
Web コントロール ライブラリ いいえ
Windows サービス はい
Web サイト いいえ

適用対象

こちらもご覧ください