Click to See Complete Forum and Search --> : Get the state of window opened by ShellExecute


nbaztec
August 13th, 2009, 03:38 AM
Hi all,
I wanna know say I opened an exe using ShellExecute(), and now I wanna wait till its finished closing how can I do this.


//I can do upto here only
HWND H;
H=ShellExecute(MainWindow,"open","Dummy.exe",NULL,NULL,SW_SHOW);

//After this i dnt know what to do

[Test if H has closed] ???


Thanks,
Nisheeth

dc_2000
August 13th, 2009, 07:43 PM
You need to use ShellExecuteEx(), check here:
http://msdn.microsoft.com/en-us/library/bb762154(VS.85).aspx

after it returns TRUE, you need to wait for the SHELLEXECUTEINFO.hProcess before you close it:

if(lpExecInfo.hProcess)
{
WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
CloseHandle(lpExecInfo.hProcess);
}


Keep in mind though, that unlike CreateProcess() the ShellExecuteEx() does not always return a process handle.