command line arguments for a windows app

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to write a windows app that accepts command line arguments. Does
anyone know if this can be done and if so, how to do it.
 
Executing a console app:

ConsoleApp.exe -switch2

with the following class produces this output:

Switch two activated.

Class definition:

public class ConsoleApp
{
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
switch (args[0].Trim().ToLower())
{
case "-switch1":
Console.WriteLine("Switch one activated.");
break;
case "-switch2":
Console.WriteLine("Switch two activated.");
break;
default:
Console.WriteLine("No options selected");
break;
}
}
else
Console.WriteLine("No options selected");
}
}
 
Will this work for a Windows Form App?

Dave said:
Executing a console app:

ConsoleApp.exe -switch2

with the following class produces this output:

Switch two activated.

Class definition:

public class ConsoleApp
{
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
switch (args[0].Trim().ToLower())
{
case "-switch1":
Console.WriteLine("Switch one activated.");
break;
case "-switch2":
Console.WriteLine("Switch two activated.");
break;
default:
Console.WriteLine("No options selected");
break;
}
}
else
Console.WriteLine("No options selected");
}
}


--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
CLEAR-RCIC said:
I want to write a windows app that accepts command line arguments. Does
anyone know if this can be done and if so, how to do it.
 
I'm not sure I understand. Winform projects don't have a Main(). Then have
a Form_Load with already take a certain number of parameters. It doesn't
allow you to overload it with more parameters.
 
CLEAR-RCIC said:
I'm not sure I understand. Winform projects don't have a Main(). Then
have
a Form_Load with already take a certain number of parameters. It doesn't
allow you to overload it with more parameters.

They most assuredly do have a Main(). Most of the time it will be calling
Application.Run on your form.

Are you using VB by chance? If you are, you might have to ask someone who
knows the langauge better as I believe the default setup generates the Main
for you instead of having it in code explicitly.
 
OK. I got it working. Thanks for the help!!!

Daniel O'Connell said:
They most assuredly do have a Main(). Most of the time it will be calling
Application.Run on your form.

Are you using VB by chance? If you are, you might have to ask someone who
knows the langauge better as I believe the default setup generates the Main
for you instead of having it in code explicitly.
 
Back
Top