I have a C# Console application project where the output type is set to "Windows application". This is so the console does not flash up at the start of the program.
However i also want to allow a help command line argument which will display details about the program if you run it from the command line with "/?" as an argument.
Is there a way to have the program run as a windows application normally but show a console if the help argument is passed?
EDIT - After reading the answers and a similar one at This question (this question assumes you are running with a console application output type) I am using this solution.
[DllImport(Kernel32_DllName)] private static extern bool AllocConsole(); [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); const int SW_HIDE = 0; const int SW_SHOW = 5; static void Main(string[] args) { if(args.Contains("/?")) { AllocConsole(); Console.WriteLine("helpText"); Console.ReadLine(); var handle = GetConsoleWindow(); //Hides console ShowWindow(handle, SW_HIDE); } }