Export (0) Print
Expand All

Interaction.Command Method

Returns the argument portion of the command line used to start Visual Basic or an executable program developed with Visual Basic. The My feature provides greater productivity and performance than the Command function. For more information, see CommandLineArgs.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

static member Command : unit -> string

Return Value

Type: System.String
Returns the argument portion of the command line used to start Visual Basic or an executable program developed with Visual Basic.
The My feature provides greater productivity and performance than the Command function. For more information, see CommandLineArgs.

After the arguments are returned, you can search for common delimiters, such as spaces, backward or forward slashes, hyphens, or quotation marks, to split or search the string for individual parameters.

For applications developed with Visual Basic and compiled to an .exe file, the Command function returns any arguments that appear after the name of the application on the command line, in this form: MyApp(cmdlineargs).

This example uses the Command function to return the command-line arguments in an object that contains an array.

Function GetCommandLineArgs() As String()
    ' Declare variables. 
    Dim separators As String = " " 
    Dim commands As String = Microsoft.VisualBasic.Interaction.Command()
    Dim args() As String = commands.Split(separators.ToCharArray)
    Return args
End Function

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.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