当使用“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”
任何帮助将理解!! 致敬!
Explorer.exe可以显示很多窗口。你需要在你的问题中缩小哪一个你可能想要关闭的问题。 – 2010-04-05 15:42:52