I have a windows forms application with a working GUI. However I want the application to be able to be started and used in a command-line interface aswell as a regular GUI application. When the application is started in an CLI the GUI shall not be used an instead relevant information will be written to the CLI-application. What I need to do this is a way to detect if the application (its exe file) is started in a CLI-application such as the regular windows CMD or started in a normal fashion such as clicking the exe file in the file explorer or using a desktop shortcut.
Preferably the detection should be done in the main method of the application such as
static class Program
{
[STAThread]
static void Main()
{
//if(application not started in a CLI-application)
Application.Run(new DriverToolApplicationContext());
//else
//Console.writeLine("Application started in CLI-application");
}
}
How is this detection best implemented? I preferably do not want to put any arguments in the main method.