Returns an array containing the command line arguments for this process.
[Visual Basic] Public Shared Function GetCommandLineArgs() As String () [C#] public static string[] GetCommandLineArgs(); [C++] public: static String* GetCommandLineArgs() []; [JScript] public static function GetCommandLineArgs() : String[];
The first element in the result is the executable file name, and the following 0 or more elements contain the command-line arguments.
Exception Type | Condition |
---|---|
NotSupportedException | if the system does not support command line arguments. |
Note that quotes are handled intelligently.
On Windows NT/2000, the name of the executable file does not include the path.
On Windows 95/98, the name of the executable file includes the path. Also, long file names (non-8dot3 names) may be shortened to their 8dot3 representation.
On Windows CE, a NotSupportedException is thrown because Windows CE does not support command-line arguments.
The following Managed C++ example demonstrates the usage of the GetCommandLine and GetCommandLineArgs methods. If this code is placed in a file named gecko.cpp, and compiled as shown in the in-source comment below, the gecko.exe that is produced can be used to both echo the entire command line to the console, and echo the command-line arguments to the console.
[C++] #import <mscorlib.dll> void main () { String *line = Environment::GetCommandLine(); [managed] String * [] args = Environment::GetCommandLineArgs(); Console::WriteLine(L"GetCommandLine() returns :"); Console::WriteLine(L"\t{0}", line); Console::WriteLine(); Console::WriteLine(L"GetCommandLineArgs() returns :"); for(int i = 0; i < args->Length; i++) Console::WriteLine(L"\t{0}", args[i]); } /* OUTPUT: D:\TEST>c:\corsdk\compiler\vc\cl.exe /EEi /c gecko.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Vers. 13.00.8565 for 80x86 COM+ Copyright (C) Microsoft Corp 1984-1999. All rights reserved. gecko.cpp D:\TEST>c:\corsdk\compiler\vc\link.exe /libpath:c:\corsdk\compiler\vc msvccee.lib gecko.obj Microsoft (R) Incremental Linker Version 7.00.8565 Copyright (C) Microsoft Corp 1992-1999. All rights reserved. D:\TEST>gecko.exe gecko -any lizard of the family Geckonid, named for the sound the animal utters. GetCommandLine() returns : gecko.exe gecko -any lizard of the family Geckonid, named for the sound the animal utters. GetCommandLineArgs() returns : gecko.exe gecko -any lizard of the family Geckonid, named for the sound the animal utters. */