語言

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)

屬性值

ReadOnlyCollection<T> A 的 String,包含當前應用程式的命令列參數字串。

範例

本範例使用 該 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 事件並檢視 CommandLine 參數的 StartupEventArgs 屬性。

Note

該 My.Application.CommandLineArgs 屬性僅回傳命令列參數。 這與屬性的行為 CommandLine 不同,屬性除了參數外還回傳應用程式名稱。

Note

在部署 ClickOnce 的應用程式中,利用 ActivationUri 物件的 My.Application.Deployment 屬性取得命令列參數。 如需詳細資訊,請參閱Deployment。

下表列出涉及該 My.Application.CommandLineArgs 屬性的任務範例。

至 看!
檢查後續嘗試啟動單一實例應用程式時的命令列參數 StartupNextInstance

依專案類型提供可用性

專案類型 Available
Windows 應用程式 Yes
類別庫 No
主控台應用程式 Yes
Windows 控件庫 No
Web 控制庫 No
Windows 服務 Yes
網站 No

適用於

另請參閱