[英]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; 尝试使用“ Process.CloseMainWindow()”方法通过另一个应用程序关闭Windows资源管理器(而非Internet Explorer)窗口时遇到问题。 because it doesn´t close the Explorer window, it tries to close the full Windows (Operative System), by the way, Windows XP.
因为它没有关闭资源管理器窗口,所以它尝试关闭整个Windows(操作系统),也就是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" 假设“ actualProcess”是“ explorer.exe”
Any help 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.
但是,您可以取消该进程,但是Windows会立即将其备份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.