Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run only one instance for FoxPro DOS application

FoxPro Enviroment

How to run only one instance for FoxPro DOS application

by  ramani  Posted    (Edited  )
The follwing will ensure that you run your application only once in your computer.

Step:1 .. In your main.prg which starts you application.. add the following as your first 5 lines.
**********************************************************
DEFINE WINDOW myApp FROM 1,1 to 5,5 NONE
ON ERROR DO myExit
MODI COMM C:\myAppl.txt WINDOW myApp NOWAIT
HIDE WINDOW myApp BOTTOM
ON ERROR && as you will follow your own ON ERROR routines
*********************************************************
Step:2 .. Then at the end of your same PRG, add the following.
*********************************************************
PROCEDURE myExit
WAIT WINDOW "Application is already running"
QUIT
*********************************************************

Step:3 .. Now create a text file "myAPp.txt" in the clients c:drive and save it. There is a need for only a single space in that file.. to avoid display of the content in the application screen.

Once the file is there, the application will open the file in read-write mode and lock it by itself. Next attempt cannot open that and so the error condition will logout the user. Even if the application, is multiuser and is in Server, the opening of myApp.txt in C drive will ensure that each usr starts only once.

Simple trick. Isn't It? :)
**********************************************************
** Ramani (Subramanian.G), FoxAcc, ramani_g@yahoo.com
** EOF
**********************************************************
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top