Advertisement

07.24.2008 at 01:06AM PDT, ID: 23591310 | Points: 250
[x]
Attachment Details

How to launch an URL (like ShellExecute) but wait until finished? (not async)

Asked by Carl_Brody in Windows Programming, Windows XP Operating System

Tags: ,

I use the win32 ShellExecute function to launch programs, images (which are opened in my default image viewer), URLs (which are opened in the browser), etc.

Works fine, but the ShellExecute function returns immediately -- it doesn't wait until the executed item is finished.

When I want it to wait, I can use the spawnv( _P_WAIT , etc) function. But now I can't just parse images or URLs anymore: unlike ShellExecute, this function really expects an executable program name. So when opening URLs, I would have to determine the system's default program to launch http:// links with, similar with images, mp3 files, etc. Sounds like a lot of unnecessary hassle.

Is there a way to launch random items (not only programs), just like ShellExecute, but something that waits until the executed item is done?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
#include <windows.h>
#include <process.h>
 
char *program = "C:\\Windows\\Notepad.exe";
char *image = "C:\\Dog.jpg";
char *url = "http://www.disneyland.com/";
 
// Works fine, all 3 launched immediately:
int show = SW_SHOWNORMAL;
ShellExecute(NULL,NULL,program,NULL,NULL,show);
ShellExecute(NULL,NULL,image,NULL,NULL,show);
ShellExecute(NULL,NULL,url,NULL,NULL,show);
 
// First works fine: (and waits until notepad closes)
// The other 2 don't do anything :(
spawnv( _P_WAIT, program, NULL );
spawnv( _P_WAIT, image, NULL );
spawnv( _P_WAIT, url, NULL );
[+][-]07.24.2008 at 07:38AM PDT, ID: 22079613

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 08:34AM PDT, ID: 22112519

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 08:38AM PDT, ID: 22112565

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.01.2008 at 01:58AM PDT, ID: 22136480

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.07.2008 at 02:55PM PDT, ID: 22185855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.11.2008 at 06:11AM PDT, ID: 22203965

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628