DotNet Friends

April 14, 2008

Hide Console Window in Console Application In C#.Net

1) Create the Console application in C# dotnet

2) Now in the static void Main(string[] args) function put the below line

//give the title of running application

Console.Title = “TestHideApplication”;

//put your console window caption here

IntPtr hWnd = FindWindow(null, ” TestHideApplication “);

if (hWnd != IntPtr.Zero)

{

//Hide the window

ShowWindow(hWnd, 0); // 0 = SW_HIDE

}

3) in the global declation put the below code

//add namespace using System.Runtime.InteropServices;

[DllImport("user32.dll")]

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]

static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

Thanks

5 Comments »

  1. hmmm.. not work at me… if u are working at C# please add me at msn : kataras2008@hotmail.com or send me e-mail at : kataras2006@hotmail.com ..

    i am 15 years old and i am learning C#…

    Comment by MakiS — September 7, 2008 @ 12:58 pm

  2. Hi Makis,
    good work Makis.
    can you describe in detail which application you use and how to apply above code in your application..

    thnx

    Comment by patriwala — September 8, 2008 @ 3:08 am

  3. [...] until finished. There are also ways to hide the Console window (check this link for example: Hide Console Window in Console Application In C#.Net « DotNet Friends) once the app is started, but a Console window will appear quickly anyway. There is also sort of a [...]

    Pingback by Command Line Execution - bytes — January 27, 2009 @ 8:52 am

  4. This solution find a console window with given title and hides it. The problem here is that it will hide all the windows matching this title. I believe a better solution would be to call a kernel32 API FreeConsole(). It will detach the console attached to the application and close it if not in use.

    Comment by dsky — January 28, 2009 @ 3:52 am

  5. thank u soooooooooooooooo much

    Comment by faid — September 18, 2009 @ 1:00 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.