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
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#…
Hi Makis,
good work Makis.
can you describe in detail which application you use and how to apply above code in your application..
thnx
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.
thank u soooooooooooooooo much
No need of any code as such. In order to hide any Console app, just open the Project Properties. Under the Application Page, change the “Output type” from Console Application to Windows Application.
Thats it. Your Console app will be forever hidden.
What if I am calling some other application not made in c# (or say .NET)?
Then you must use the technique described here :-
http://www.codeproject.com/KB/winsdk/runsilent.aspx
———————————————————-
Yep this is the best way to do it. No code needed
This information is indeed usefull when you are using atistream on win>XP.
The driver has the very annoying feature: it requires an attached console in order to not to crash on building opencl code.
THIS is the solution I was looking for my C#.Net Console app to Hide.
Thanks a lot
It worked. Good work
Nice one.
But I would not use FindWindow:
There is a function for that: GetConsoleWindow() in kernel32.dll.
Retrieves handle of console window owned by current process.
[DllImport("kernel32")]
static extern IntPtr GetConsoleWindow();
returns IntPtr.Zero if current process does not have a console window.