Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winform command line argument returning executable filename

I am trying to pass a command line argument to a winform I have but no matter what I specify as the parameter it keeps returning the winform filename and path.

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(Environment.GetCommandLineArgs()[0]);
}

The messagebox will show C:\App\MyApp.exe even if at a cmd I type C:\App\MyApp.exe param1 which should output param1.

like image 913
Bali C Avatar asked Dec 23 '11 19:12

Bali C


1 Answers

You are not doing anything wrong.

The first argument on the command line is always the executable name.

To get the first argument passed to the executable, get the next parameter (assuming one exists):

Environment.GetCommandLineArgs()[1]
like image 179
Oded Avatar answered Sep 18 '22 12:09

Oded