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
.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With