2010-04-05 208 views
1

当使用“Process.CloseMainWindow()”方法试图通过另一个应用程序关闭Windows资源管理器(而非Internet Explorer)窗口时,我遇到问题;因为它没有关闭资源管理器窗口,所以它试图关闭Windows(操作系统),顺便说一下,Windows XP。CloseMainWindow()关闭Windows资源管理器窗口的问题

的代码如下:

[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; 

    } 

假设 “actualProcess” 是 “的explorer.exe”

任何帮助将理解!! 致敬!

+0

Explorer.exe可以显示很多窗口。你需要在你的问题中缩小哪一个你可能想要关闭的问题。 – 2010-04-05 15:42:52

回答

1

我相信这是因为探索的主窗口被认为是壳。但是,你可以杀死这个进程,但是Windows会立即启动它。

+0

杀死方法工作,它关闭浏览器窗口,它并没有启动它,但我想知道是否有一个不太关键的方式来关闭浏览器窗口。 谢谢! – MorgoZ 2010-04-06 07:22:41

+0

你试图完成什么 – rerun 2010-04-12 13:13:45

相关问题