I use this code to start the webbrowser and then terminate it. However instead, after having started the webbrowser and making it the active window, it catches the window in the background (the application that starts the browser) and terminates it. So I want it to terminate the window in the forground (the webbrowser) instead.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\iexplore.exe";
ShExecInfo.lpParameters = "http://www.google.se";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWMAXIMIZED;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,10);
DWORD Pid = GetCurrentProcessId();
HANDLE h = OpenProcess(PROCESS_TERMINATE, false, Pid);
TerminateProcess(h, 1);
CloseHandle(h);
I guess the problem is that GetCurrentProcessId() gives me the id of the running application and not the newly opened webbrowser. Why is that?