Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 210081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:58:23+00:00 2026-05-11T17:58:23+00:00

Is there a way to launch a C# application with the following features? It

  • 0

Is there a way to launch a C# application with the following features?

  1. It determines by command-line parameters whether it is a windowed or console app
  2. It doesn’t show a console when it is asked to be windowed and doesn’t show a GUI window when it is running from the console.

For example,

myapp.exe /help

would output to stdout on the console you used, but

myapp.exe

by itself would launch my Winforms or WPF user interface.

The best answers I know of so far involve having two separate exe and use IPC, but that feels really hacky.

What options do I have and trade-offs can I make to get the behavior described in the example above? I’m open to ideas that are Winform-specific or WPF-specific, too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:58:24+00:00Added an answer on May 11, 2026 at 5:58 pm

    Make the app a regular windows app, and create a console on the fly if needed.

    More details at this link (code below from there)

    using System;
    using System.Windows.Forms;
    
    namespace WindowsApplication1 {
      static class Program {
        [STAThread]
        static void Main(string[] args) {
          if (args.Length > 0) {
            // Command line given, display console
            if ( !AttachConsole(-1) ) { // Attach to an parent process console
               AllocConsole(); // Alloc a new console
            }
    
            ConsoleMain(args);
          }
          else {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
          }
        }
        private static void ConsoleMain(string[] args) {
          Console.WriteLine("Command line = {0}", Environment.CommandLine);
          for (int ix = 0; ix < args.Length; ++ix)
            Console.WriteLine("Argument{0} = {1}", ix + 1, args[ix]);
          Console.ReadLine();
        }
    
        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern bool AllocConsole();
    
        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern bool AttachConsole(int pid);
    
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to launch a gnome-terminal from the command line (i.e., using
I am not sure whether there is a way to Launch an external application,
Is there a way to launch a desktop application from a Metro-style app on
Is there any way to automatically launch an application on USB attach or CD
I'm trying to launch another application from C# application, is there a way to
Is there a way to launch an application through Intelli-J so that it makes
I'm writing an application for iOS4. Is there any fast way to launch an
Is there any way to launch get a BREW application started according to a
Is there any way to launch a program with a shortcut, that sets the
Is there a way I can have a custom quick launch menu on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.