Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Waiting for entire file to appear before execution

Posted on 2011-03-02
3
Medium Priority
?
310 Views
Last Modified: 2012-05-11
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
Comment
Question by:JoeD77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 35020384
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
 
LVL 35

Expert Comment

by:sarabande
ID: 35026510
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
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 35029482
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question