Friday, May 6, 2011

Get Command Line Arguments

Generally programs in Windows can be called with various arguments, which are called command line arguments.
For example some programs can be called directly with the file which is to be opened.
In console applications this arguments are directly accessible as parameters of the function Main().
In Windows Forms Application they are not, but we can get them with the function Environment.GetCommandLineArgs(), which returns the command line arguments as an array of the stype string.
The following code reads-out the passed arguments at program start:

string[] CommandLineArgs = Environment.GetCommandLineArgs();

As you can see, as first parameter always path and name of the executing program is  set.

No comments:

Post a Comment