Stef Merlijn
asked on
Allow only one instance of the program to be started on network.
Hi,
My application is installed on a network-drive. End-users can startup this application from their local computer using a shortcut. ** I don't want to allow multiple instances of my application to be started.
After user-A has started the application on local computer-1, it is not sufficient to check for a running instance of this application on local computer-2, because that instance will not be recognized on local computer-2 (as it is running locally on computer-1).
I've thought about creating a controle-file the moment the application is started by any user/local computer and delete this file after the application is closed again. But this might give some timing-problems when two users start the application at the same time.
How can I solve this problem in an easy but certain/secure way?
Regards, Stef
My application is installed on a network-drive. End-users can startup this application from their local computer using a shortcut. ** I don't want to allow multiple instances of my application to be started.
After user-A has started the application on local computer-1, it is not sufficient to check for a running instance of this application on local computer-2, because that instance will not be recognized on local computer-2 (as it is running locally on computer-1).
I've thought about creating a controle-file the moment the application is started by any user/local computer and delete this file after the application is closed again. But this might give some timing-problems when two users start the application at the same time.
How can I solve this problem in an easy but certain/secure way?
Regards, Stef
ASKER
It would be nice to have a bit more of a solution (code example).
In other words: how to handle checking for an existing instance of the application?
In other words: how to handle checking for an existing instance of the application?
See this link for more information
http://www.delphipages.com/threads/thread.cfm?ID=156610&G=156610&SAR=TRUE
http://www.delphipages.com/threads/thread.cfm?ID=156610&G=156610&SAR=TRUE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SteveBay: What is the use of the timer, I don't see where it is actually used in your code?
ASKER
Another question.
What if the application crashes because of an error, will 'InUse.fil' be freed?
If not: how to free it?
What if the application crashes because of an error, will 'InUse.fil' be freed?
If not: how to free it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a question, but if your application crashes there is no graceful shutdown, no other events in the app are processed and I believe that the InUse.fil will still be there and Windows will still show the file as locked.
No other app will run since it is still locked or until Windows does a reboot.
I am not certain if Windows releases this kind of locking after a crash.
Just a comment for my further understanding if anyone knows!
John
No other app will run since it is still locked or until Windows does a reboot.
I am not certain if Windows releases this kind of locking after a crash.
Just a comment for my further understanding if anyone knows!
John
ASKER
Thank you very much for your help.
That is difficult to test, however, I crashed the program with an access violation and Task manager and the file was no longer in use. I believe that there are circumstances where the OS will continue to hold the file after the application crashes. Then the machine that was running the application may have to be logged off and back on.
Thanks Steve for the reply. I believe that to be true also and was wondering about that. I have had the same results; sometimes still locked and other times no problem.
Gotta love Windows! :)
John
Gotta love Windows! :)
John
If you create the file with a TFileStream, with mode fmShareExclusive, you are sure only one user can open the file.
from the help:
fmShareExclusive Other applications can not open the file for any reason.