C# 控制台隐藏程序窗口

using System;
using System.Runtime.InteropServices;

namespace Test
{
    class Program
    {
        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
        static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        static void Main(string[] args)
        {
            #region 隐藏本体窗口
            Console.Title = "SysGreenBackService";
            IntPtr intptr = FindWindow("ConsoleWindowClass", "SysGreenBackService");
            if (intptr != IntPtr.Zero)
            {
                ShowWindow(intptr, 0);//隐藏这个窗口
            }
            string x;
            x = Console.ReadLine();
            #endregion
         }
    }

你可能感兴趣的:(C# 控制台隐藏程序窗口)