how to wait for shellExecute to finsih??

Ahmed_mahmoud
Ahmed_mahmoud used Ask the Experts™
on
Good Morning...
i am calling ShellExecute() to call rar.exe to compress a file. then i do some processing on the compressed file...
the problem is shellExecute returns before the compressed file is written (rar was still running), so, when i do the processing, i get error messages, because rar is not yet finished!!

how can i correct this? is there a certain parameter to do that in ShellExecute()? or is there another function?

thank you very much in advance...
urs...
Ahmed Mahmoud
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
i.e. ShellExecute returns immediately after the called program runs! it doesn't wait for it to finish!!
how can i tell it to wait for the application to finish?

thank you! :)
Commented:
Sorry, you can't using ShellExecute().

As an alternative, use ShellExectuteEx().  The hProcess member of the SHELLEXECUTEINFO struct used by this function will give you a handle to the created process.  You can then use that handle in a WaitForSingleObject() call to cause your app to wait on the new process to complete.

Commented:
Use ShellExecuteEx. It writes created process handle to SHELLEXECUTEINFO::hProcess. After this call wait for the end of the process:

WaitForSingleObject(lpExecInfo->hProcess, INFINITE);

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Commented:
I wish I'd said that..... ;-)
Hi, Ahmed_mahmoud

in case, you cannot find any way, what u can do is to have a batch file or a program that runs the rar.exe and when it is finished create a file.

rar.exe somefile etc.
echo mutex > mutex.dat

then ur program will check for this file, if it exists already that means rar has ended. then u are required to delete this mutex.dat file so that next time u can create it again

=======CoolBreeze=======
== Cool It, the Breeze is here  ==
=====================
Hi, Ahmed_mahmoud

in case, you cannot find any way, what u can do is to have a batch file or a program that runs the rar.exe and when it is finished create a file.

rar.exe somefile etc.
echo mutex > mutex.dat

then ur program will check for this file, if it exists already that means rar has ended. then u are required to delete this mutex.dat file so that next time u can create it again

=======CoolBreeze=======
== Cool It, the Breeze is here  ==
=====================

Commented:
To jhance: Sorry, I didn't copy your answer, we did this at the same time. I happens sometimes...

Commented:
I know...  Hence the ";-)"
AndyAinscowFreelance programmer / Consultant

Commented:
Have a look at the CreateProcess call.  You can set lots of parameters and you can then use the process created and WaitForSingleObject with an INFINITE wait param that will hold your code until the process finishes.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial