C++ ShellExecute/CreateProcess check/timeout browser load of a web site
Using vanilla c++ (no .net or mfc) create/complete a simple window
application that waits for a programmatic connection (using
ShellExecute / ShellExecuteEx or CreateProcess) to a specific web site
(using iexplore or firefox) to be established and times out if the
specific web site does not completely load into either browser. Note
that a "two step" solution is not good for me - example of a two step
solution is using a "ping" and then a browser open.
My attempts below do not work - while they do open a new browser
window the wait / check connection fails - this is a "well known"
problem as CreateProcess will create a new process and return success
if "iexplore.exe" is found and executed independent of whether the web
site is found and independnet of whether an internet connection is
present.
#include "stdafx.h"
#include <shellapi.h>
#include "stdafx.h"
#define IE_MAXWAIT 9000
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here. max
SHELLEXECUTEINFO ShExecInfo = {0}; // must include shellapi.h
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; // ShExecInfo.hProcess ==
null if SEE_MASK_NOCLOSEPROCESS not set
// ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT ;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\Program Files\\Internet
Explorer\\iexplore.exe"; // don't understand why this keeps failing on
Intersil Home Page even with 60secs wait
ShExecInfo.lpParameters = "://www.google.com";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWMAXIMIZED; // note: ShellExecuteEx only
maximises executables with the show parameter
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
// CloseHandle(ShExecInfo.hProcess); //close Process
DWORD retVal = WaitForSingleObject(ShExecInfo.hProcess,IE_MAXWAIT); //
IE_MAXWAIT time-out interval in milliseconds
// DWORD retVal = WaitForInputIdle(ShExecInfo.hProcess,IE_MAXWAIT); //
IE_MAXWAIT time-out interval in milliseconds
// check for WaitForSingleObject wait result
if (retVal > 0)
// if (retVal == WAIT_FAILED)
// if (retVal != WAIT_OBJECT_0)
// if (retVal == WAIT_TIMEOUT)
MessageBox(NULL,"WAIT_FAILED","Failed",MB_OK|MB_ICONEXCLAMATION);
else
MessageBox(NULL,"WAIT_FAILED","Pass",MB_OK|MB_ICONEXCLAMATION);
return 0;
}
#include "stdafx.h"
#include <shellapi.h>
#include "stdafx.h"
#define IE_MAXWAIT 5000
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
SHELLEXECUTEINFO ShExecInfo = {0}; // must include shellapi.h
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\MININT\\SYSTEM32\\notepad.exe"; // don't
understand why this keeps failing on Intersil Home Page even with
60secs wait
// ShExecInfo.lpFile = "C:\\Program Files\\Internet
Explorer\\iexplore.exe"; // don't understand why this keeps failing on
Intersil Home Page even with 60secs wait
// ShExecInfo.lpFile = "://www.google.com"; // this passes but the
window restores to the size last closed at
ShExecInfo.lpParameters = "C:\\MININT\\SYSTEM32\\test.txt";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWMAXIMIZED; // note: ShellExecuteEx only
maximises executables with the show parameter
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
DWORD retVal = WaitForSingleObject(ShExecInfo.hProcess,IE_MAXWAIT); //
IE_MAXWAIT time-out interval in milliseconds
// check for WaitForSingleObject wait result
if (retVal == WAIT_FAILED)
// if (retVal != WAIT_OBJECT_0)
MessageBox(NULL,"WAIT_FAILED","Failed",MB_OK|MB_ICONEXCLAMATION);
else
MessageBox(NULL,"WAIT_FAILED","Pass",MB_OK|MB_ICONEXCLAMATION);
return 0;
} |