Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Waiting for entire file to appear before execution

Hello,
I'm trying to wait until an application is downloaded before executing it. Unfortunately, I'm having problems because it will execute the file before the application is fully downloaded.

here's my current code:

char cpath[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, cpath);
	HANDLE  m_hDir = FindFirstChangeNotification(cpath, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME);
WaitForSingleObject(m_hDir, INFINITE);

			Sleep(4000);

			WinExec("app.exe", SW_SHOW);
			

Open in new window


As you can see, I'm forced to use Sleep() to give it enough time to fully download, but I'd like a more reliable way of doing this. I thought of checking for the full size of the desired file before execution, but the file being downloaded may vary in size a great deal, so that wouldn't be sensible either.

Any input would be helpful


Thanks.
0
JoeD77
Asked:
JoeD77
1 Solution
 
jkrCommented:
How are you downloading the file? Waiting for that operation to finish seems to be the better way to approach this issue, e.g.
URLDownloadToFile(NULL,"http://www.example.org/path/app.exe","app.exe",0,NULL);

WinExec("app.exe", SW_SHOW);

Open in new window

0
 
sarabandeCommented:
you could try to open the exe file exclusively. if that works the file is closed.

another idea is to download the file using a different name  (or extension) if you have control of the download process. then wait on change file name notification.

Sara
0
 
Deepu AbrahamR & D Engineering ManagerCommented:
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now