ConsoleApplicationBase.CommandLineArgs Property

Gets a collection containing the command-line arguments as strings for the current application.

Namespace: Microsoft.VisualBasic.ApplicationServices
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public ReadOnlyCollection<string> CommandLineArgs { get; }
/** @property */
public ReadOnlyCollection<String> get_CommandLineArgs ()

public function get CommandLineArgs () : ReadOnlyCollection<String>

Not applicable.

Property Value

A ReadOnlyCollection of String, containing the command-line arguments as strings for the current application.

For more detailed information, see the Visual Basic topic My.Application.CommandLineArgs Property.

The My.Application.CommandLineArgs property provides read-only access to the current application's command-line arguments for applications that are not ClickOnce deployed.

For a single-instance application, the My.Application.CommandLineArgs property returns the command-line arguments for the first instance of an application. To access the arguments for subsequent attempts to start a single-instance application, you must handle the My.Application.StartupNextInstance Event and examine the CommandLine property of the StartupEventArgs argument.


The My.Application.CommandLineArgs property returns only the command-line arguments. This is different from the behavior of the CommandLine property, which returns the application name in addition to the arguments.


In an application that is ClickOnce deployed, use the ActivationUri property of the My.Application.Deployment object to get the command-line arguments. For more information, see My.Application.Deployment Property.

The following table lists examples of tasks involving the My.Application.CommandLineArgs property.



Check if the application started with the string /batch as an argument

How to: Enable a Batch Mode for Window Forms Applications

Check the command-line arguments of subsequent attempts to start a single-instance application

My.Application.StartupNextInstance Event

This example uses the My.Application.CommandLineArgs property to examine the application's command-line arguments. If an argument is found that starts with /input=, the rest of that argument is displayed.

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

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions