Company logo


Advice, tips, techniques and downloads for Visual Foxpro developers.

Home | Contact

Versión en español de este artículo

Installing new copies of VFP executables

How to install updated EXE files without forcing users to log out of your application

Have you ever needed to install a new copy of an EXE file after an application has gone live? If so, you will know that you cannot simply copy the new file over the existing one. If you try to do that while users are running the application, Windows will report a file sharing violation. Your only recourse will be to wait until everyone has logged out, which could be inconvenient.

Andew Connor, the IT Manager at Mids & Horsey Ltd. in the UK, has come up with a simple solution to this problem. Andrew suggests that you supply a small loader program which searches the executable directory for the latest version of the EXE file. Once it has found it, it hands over control to that file and thus runs the application in the normal way.

The loader program is a simple Visual FoxPro PRG. It is completely generic - it doesn't need to know the name of the target EXE file or the directory that contains it. However, you do need to follow a simple naming convention.

Naming the files

The loader program must be compiled into an EXE file, the name of which must be that of the main application. This is the file that the users will launch when they want to run the application.

For the name of the application's actual EXE file, use the application name followed by a two-digit version number. So, if the application is called SALES, the loader program will be SALES.EXE. The main EXE file might then be SALES01.EXE, SALES02.EXE, and so on. Each time you want to distribute a new version of the main EXE, just change the version number.

Your version numbers can be any numbers you like - they don't have to be consecutive or in ascending order. But they must always be exactly two digits.

Be sure to place the loader's EXE file in the same directory as the main executable file. Then simply arrange for the users to run the loader whenever they want to launch the application.

The code

Here then is the code for the loader program. You can paste this code into a PRG file and then build it to an EXE.

* Generic loader program.

LOCAL lcExecPath, lcFileName, lcSkeleton, lnFileCount
LOCAL lcExe, ltLatest, lnI
LOCAL ARRAY laFiles(1)

* Get the path to the executable directory
lcExecPath = JUSTPATH(SYS(16))

* Make that the default

* Get the root name of the exectuable program
lcFileName = JUSTSTEM(SYS(16))

* Build an array of all possible EXE names
lcSkeleton = lcFileName+"??.EXE"
   && lcSkeleton is the wildcard file spec for ADIR()
lnFileCount = ADIR(laFiles,lcSkeleton)

* Look for the most recent EXE file
lcEXE = ""
ltLatest = {}
FOR lnI = 1 TO lnFileCount
  IF FDATE(laFiles(lnI,1),1) > ltLatest
    ltLatest = FDATE(laFiles(lnI,1),1)
    lcExe = laFiles(lnI,1)

* Launch the most recent EXE file
  DO (lcEXE)

As you can see, the loader program builds an array containing the names of all the EXE files that follow the naming convention. It then hands over control to the most recent of those files.

Updating the application

From now on, whenever you want to distribute a new version of the application, you can just copy the updated EXE file to the executable directory. As this will have a different version number from the existing file, you can do this even while the users are working in the application. The next time that a user launches the application, the loader will automatically find the correct version. In due course, you can delete the old version.

Mike Lewis Consultants Ltd. May 2003

More Visual FoxPro articles | Crystal Reports articles | Recommended books | Visual FoxPro consultancy | Contact us

FoxStuff is maintained by Mike Lewis Consultants Ltd. as a service to the VFP community. Feel free to download and use any code or components, and to pass around copies of the articles (but please do not remove our copyright notices or disclaimers).

The information given on this site has been carefully checked and is believed to be correct, but no legal liability can be accepted for its use. Do not use code, components or techniques unless you are satisfied that they will work correctly in your applications.

© Copyright Mike Lewis Consultants Ltd.