Export (0) Print
Expand All

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)

member CommandLineArgs : ReadOnlyCollection<string> with get

Property Value

Type: System.Collections.ObjectModel.ReadOnlyCollection(String)
A ReadOnlyCollection(T) of String, containing the command-line arguments as strings for the current application.

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 StartupNextInstance event and examine the CommandLine property of the StartupEventArgs argument.

NoteNote

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.

NoteNote

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 Deployment.

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

To

See

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

StartupNextInstance

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

No

Console Application

Yes

Windows Control Library

No

Web Control Library

No

Windows Service

Yes

Web Site

No

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 
    Next 

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft