The other day I had to update a existing windows GUI application to enable it to be called via the command line. In order to do this, you need to add the following import to your .NET application (C# example shown):
/// AttachConsole gives the ability for a GUI application to write to the console window of the console from which it was started.
static extern bool AttachConsole(uint dwProcessId);
/// Flag indicating that we should attach to parent console
const uint ATTACH_PARENT_PROCESS = 0x0ffffffff;
After adding these declarations to your main class, its a simple case of adapting your Main method to detect if you're running in console or GUI mode and acting accordingly. E.g:
/// The main entry point for the application.
static void Main(string args)
// Are we in console mode
bool isConsole = args.Length > 0;
// Attach to console
// Run console app