Google Answers Logo
View Question
 
Q: C++ ShellExecute/CreateProcess check/timeout browser load of a web site ( No Answer,   3 Comments )
Question  
Subject: C++ ShellExecute/CreateProcess check/timeout browser load of a web site
Category: Computers > Programming
Asked by: fdryan-ga
List Price: $49.50
Posted: 21 Jul 2006 12:20 PDT
Expires: 20 Aug 2006 12:20 PDT
Question ID: 748342
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;
}
Answer  
There is no answer at this time.

Comments  
Subject: Re: C++ ShellExecute/CreateProcess check/timeout browser load of a web site
From: elondaits-ga on 24 Jul 2006 19:09 PDT
 
Do you need the program to work both with Firefox and IE, or will
either one sufice?

I think I can do it for IE, but the solution I'm thinking of won't work for Firefox.
Subject: Re: C++ ShellExecute/CreateProcess check/timeout browser load of a web site
From: elondaits-ga on 24 Jul 2006 19:18 PDT
 
Oops... I just found out you have to be a "Researcher" to be able to
post an answer... and I'm not, so I won't be able to anyway.

Good luck with getting an answer.

I can tell you what my approach would have been though:

- The IE Browser COM Component generates a COM event when a page
finishes loading. You can tell the component to load the page and
capture the event when it's done rendering.

- If I'm not mistaken, you can programatically start an instance of IE
as a COM server (I did this with the IE browser Component many
times... but I think it can be done with the IE program as well).

- If so, you'd only need to load IE using COM, hook the event, and
make it load the page. When it finishes, you end the program while
leaving the IE on.
Subject: Re: C++ ShellExecute/CreateProcess check/timeout browser load of a web site
From: fdryan-ga on 25 Jul 2006 07:56 PDT
 
Thanks for your comment Elondaits-ga,

Firefox now owns > 10% of the browser space so Firefox support is a
must.  Therefore, as you pointed out, using an IE Browser COM
Component is not an option for me.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy