Problem with Killing windows explorer?

前端 未结 5 579
梦毁少年i
梦毁少年i 2020-12-17 02:34

I need to kill windows explorer\'s process (explorer.exe), for that

lets say i use a native NT method TerminateProcess

It works but the problem is that the

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 02:39

    The "real" solution. (Complete program. Tested to work on Windows 7.)

    using System;
    using System.Runtime.InteropServices;
    
    namespace ExplorerZap
    {
        class Program
        {
            [DllImport("user32.dll")]
            public static extern int FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll")]
            public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
    
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("user32.dll", SetLastError = true)]
            public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
    
            static void Main(string[] args)
            {
                int hwnd;
                hwnd = FindWindow("Progman", null);
                PostMessage(hwnd, /*WM_QUIT*/ 0x12, 0, 0);
                return;
            }
        }
    }
    

提交回复
热议问题