开发者

Problems with CloseMainWindow() to close a Windows Explorer window

I´m facing a problem when trying to close a Windows Explorer (not Internet Explorer) window through another application, using the "Process.CloseMainWindow()" method; because it doesn´t close the Explorer window, it tries to close the full Windows (Operative System), by the way, Windows XP.

The code is as follows:

[DllImport("user32.dll")]
    static extern int GetForegroundWindow();

    [DllImport("user32.dll")]
    private static extern UInt32 GetWindowThreadProcessId(Int32 hWnd, out Int32 lpdwProcessId);


    public String[] exeCommand()
    {

        try
        {
            //Get App
            Int32 hwnd = 0;
            hwnd = GetForegroundWindow();
            Process actualProcess = Process.GetProcessById(GetWindowProcessID(hwnd));

            //Close App
            if (!actualProcess.CloseMainWindow())
                actualProcess.Kill();

        }
        catch { throw; }

        return null;

    }

Suppose that the "actualProcess" is "explorer.exe"

Any help开发者_Go百科 will be appreciated!! Salutes!


I believe this is because the main window for explore is considered the shell. You can however kill the process, but windows will start it right back up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜