usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Runtime.InteropServices;namespacehideconsole{classProgram {Static voidMain (string[] args) {Console.title="Hideconsole"; INTPTR hwnd= FindWindow (NULL, Console.title); if(hwnd! =IntPtr.Zero) ShowWindow (hwnd, cmdshow.sw_hide); //process P = new process (); /////cmd name //p.startinfo.filename = process.getcurrentprocess (). Mainmodule.modulename; //P.startinfo.createnowindow = true; //p.startinfo.windowstyle = Processwindowstyle.hidden;Console.WriteLine ("Console Application Hide DOS interface"); Console.readkey (); } #regionWinAPI/// <summary> ///sets the specified window ' s show state. /// </summary> /// <param name= "HWnd" >A handle to the window.</param> /// <param name= "nCmdShow" >Controls How the window was to be shown. This parameter is ignored the first time a application calls ShowWindow, if the program that launched the application Pro Vides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should being the value obtained by the WinMain function in its ncmd Show parameter. In subsequent calls</param> /// <returns></returns>[DllImport ("User32.dll", EntryPoint ="ShowWindow")] Private Static extern BOOLShowWindow (IntPtr hWnd, cmdshow ncmdshow); /// <summary> ///retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does is not a search child for Windows. This function does not perform a case-sensitive search. /// </summary> /// <param name= "Lpclassname" >The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must is in the Low-order word of lpclassname; The High-order word must is zero. ///If lpclassname points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or registerclassex, or any of the predefined Control-class NA Mes. ///If Lpclassname is NULL, it finds any window whose title matches the Lpwindowname parameter.</param> /// <param name= "Lpwindowname" >The window name (the window ' s title). If This parameter are NULL, all window names match.</param> /// <returns>If The function succeeds, the return value is a handle to the window which has the specified class name and window name . ///If The function fails, the return value is NULL.</returns>[DllImport ("user32.dll")] Public Static externIntPtr FindWindow (stringLpclassname,stringlpwindowname); #endregion } /// <summary> /// http://msdn.microsoft.com/en-us/library/ms633548(vs.85). aspx/// </summary> Public enumCmdshow:int { /// <summary> ///hides the window and activates another window. /// </summary>Sw_hide =0, /// <summary> ///activates and displays a window. If the window is minimized or maximized, the system restores it original size and position. An application should specify this flag is displaying the window for the first time. /// </summary>Sw_shownormal =1, /// <summary> ///Activates the window and displays it as a minimized window. /// </summary>sw_showminimized =2, /// <summary> ///Activates the window and displays it as a maximized window. /// </summary>sw_showmaximized =3, /// <summary> ///displays a window in it most recent size and position. This value was similar to Sw_shownormal, except the window was not activated. /// </summary>Sw_shownoactivate =4, /// <summary> ///Activates the window and displays it in its current size and position. /// </summary>Sw_show =5, /// <summary> ///minimizes the specified window and activates the next top-level window in the Z order. /// </summary>Sw_minimize =6, /// <summary> ///Displays the window as a minimized window. This value was similar to sw_showminimized, except the window was not activated. /// </summary>Sw_showminnoactive =7, /// <summary> ///Displays the window in its current size and position. This value was similar to Sw_show, except the window was not activated. /// </summary>Sw_showna =8, /// <summary> ///activates and displays the window. If the window is minimized or maximized, the system restores it original size and position. An application should specify this flag when restoring a minimized window. /// </summary>Sw_restore =9, /// <summary> ///sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess functio n by the program that started the application. /// </summary>Sw_showdefault =Ten, /// <summary> ///minimizes a window, even if the thread that owns the window was not responding. This flag should only is used when the minimizing windows from a different thread. /// </summary>Sw_forceminimize = One }}
C # Hide Console Application