0

I compiled a C# program to an exe file. When I double-click the exe file from windows explorer, the program starts along with a black command line window. How can I start this file from windows explorer without showing the command line window

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    
    private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    private const int HIDE = 0;
    private const int MAXIMIZE = 3;
    private const int MINIMIZE = 6;
    private const int RESTORE = 9;
    
    Process cmd = new Process();
    cmd.StartInfo.FileName = Path.Combine(path, "Launcher.exe");
    cmd.StartInfo.RedirectStandardInput = true;
    cmd.StartInfo.CreateNoWindow = true;
    cmd.StartInfo.UseShellExecute = false;
    cmd.Start();
    cmd.StandardInput.WriteLine(argHandlerArgs);
    cmd.StandardInput.Flush();
    cmd.StandardInput.Close();
    
    ShowWindow(cmd.MainWindowHandle, 0);
user173092
  • 127
  • 1
  • 1
  • 9
  • Its a duplicate of below stack overflow flow issue https://stackoverflow.com/questions/3571627/show-hide-the-console-window-of-a-c-sharp-console-application – Sukhpinder Singh Aug 13 '20 at 20:31

2 Answers2

0

If this is Windows Forms that youre talking about, then in the project properties you set the output type to Windows Application

enter image description here

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
0

You can use ShowWindowApi to hide your command line.

Here is an example

using System.Runtime.InteropServices

class CommandLine
{

    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("Kernel32")]
    private static extern IntPtr GetConsoleWindow();

    const int SW_HIDE=0;
    const int SW_SHOW=5;

    static void Main(string[] args)
    {
         IntPtr hwnd;
         hwnd=GetConsoleWindow();
         ShowWindow(hwnd,SW_HIDE);
    }
}
Tornike Gomareli
  • 1,564
  • 2
  • 16
  • 28