ConsoleApplicationBase.CommandLineArgs 屬性

定義

取得集合,包含做為目前應用程式之字串 (String) 的命令列引數。

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 事件並檢查 CommandLine 自變數的 StartupEventArgs 屬性。

注意

屬性 My.Application.CommandLineArgs 只會傳回命令行自變數。 這與 屬性的行為 CommandLine 不同,除了自變數之外,還會傳回應用程式名稱。

注意

在已部署 ClickOnce 的應用程式中,使用 ActivationUri 對象的 屬性 My.Application.Deployment 來取得命令行自變數。 如需詳細資訊,請參閱Deployment

下表列出涉及 My.Application.CommandLineArgs 屬性的工作範例。

收件者 請參閱
檢查後續嘗試啟動單一實例應用程式的命令行自變數 StartupNextInstance

依專案類型的可用性

專案類型 可用
Windows 應用程式
類別庫
主控台應用程式
Windows 控制項程式庫
Web 控制項程式庫
Windows 服務
網站

適用於

另請參閱