I would like a Windows Forms application that will contain a UI, but I want it to run from the command line with some parameters, possibly also a /hide
or /visible=false
option.
How is it possible to read in the command line parameters? And adjust accordingly?
If you change this default Main signature:
[STAThread]
static void Main()
To this:
[STAThread]
static void Main(String[] args)
You can access the commandline variables as you would from a normal console app, or if you want to access them from elsewhere you can use:
System.Environment.GetCommandLineArgs();
[STAThread]
static void Main(string[] args)
{
if (args.Length == 0)
{
// Run the application in a windows form
Application.Run(new MainForm( ));
}
else
{
// Run app from CLI
Console.WriteLine(DoStuff(args));
}
}
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