int terminateIe() { std::vector<HWND> allWindows; getTopLevelWindows(&allWindows); // Wait until all open windows are gone. Common case, no worries while (allWindows.size() > 0) { allWindows.clear(); getTopLevelWindows(&allWindows); for (vector<HWND>::iterator curr = allWindows.begin(); curr != allWindows.end(); curr++) { SendMessage(*curr, WM_CLOSE, NULL, NULL); } // Pause to allow IE to process the message. If we don't do this and // we're using IE 8, and "Restore previous session" is enabled (an // increasingly common state) then a modal system dialog will be // displayed to the user. Not what we want. wait(500); } // If it's longer than this, we're on a very strange system wchar_t taskkillPath[256]; if (!ExpandEnvironmentStrings(L"%SystemRoot%\\system32\\taskkill.exe", taskkillPath, 256)) { cerr << "Unable to find taskkill application" << endl; return EUNHANDLEDERROR; } std::wstring args = L" /f /im iexplore.exe"; STARTUPINFO startup_info; memset(&startup_info, 0, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); PROCESS_INFORMATION process_info; if (!CreateProcessW(taskkillPath, &args[0], NULL, NULL, false, DETACHED_PROCESS, NULL, NULL, &startup_info, &process_info)) { cerr << "Could not execute taskkill. Bailing: " << GetLastError() << endl; return EUNHANDLEDERROR; } WaitForSingleObject(process_info.hProcess, INFINITE); CloseHandle(process_info.hThread); CloseHandle(process_info.hProcess); return SUCCESS; }
Client::Client() : UIA(NULL), future(), watcher() { QThreadPool::globalInstance()->setExpiryTimeout(-1); connect(&watcher, SIGNAL( finished() ), SLOT( getTopLevelWindows() )); }