0
我使用此代碼來啓動網頁瀏覽器,然後終止它。然而,相反,在啓動瀏覽器並將其設置爲活動窗口後,它會捕獲後臺(啓動瀏覽器的應用程序)窗口並終止它。所以我希望它終止在forground(網頁瀏覽器)的窗口。終止ShellExecuteEx終止「錯誤的」窗口
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);
我想這個問題是GetCurrentProcessId()給我的正在運行的應用的ID,而不是新開的網頁瀏覽器。這是爲什麼?
* GetCurrentProcessId()給我的正在運行的應用程序的ID * - 是的,那是什麼*當前*的意思。 'ShExecInfo.hProcess'是進程執行的任何操作。 –