Single program instance per (windows) user.
Hello,
We have an RMI client application running on Windows XP and Windows Vista machines.
We would like users to be able to run only one instance of the program on a single computer.
We have currently implemented this by giving an error message on startup of the client when the RMI port is in use.
(If we just take another port, multiple clients can be started with no problem.)
Under Vista multiple users are allowed to login and run programs on the same computer.
But the problem is that with our implementation only one user can start the client, and when another user tries to start a client he gets the error message.
Any ideas?
[684 byte] By [
Strider80a] at [2007-11-27 4:10:05]

Thanks. We already have an application data directory (with %appdata%) so that won't be too hard to make.
But like you said I don't like it when it fails if the application crashes.
Maybe I could open a file for writing, and windows will release it when the app crashes? Will that fail with an already in use exception if the app is already running?
I would also have to check what happens with roaming profiles, the app directory may be on a network drive.
I don't wish to restrict a windows user (such as adminstrator!) to only have one instance of the program running on the whole network.
I solved it with lock files in the directory %userprofile% (System.getenv("userprofile")) which gives a local directory for me. The directory %appdata% gives a roaming profile directory.
Instead of checking for existence of a lock file I try to create a file and request a Lock on it with the FileLock and FileChannel classes. (Just creating and keeping a PrintStream instance didn't work!)
No problem with app crashes: the lock is released automatically.
I'm giving the dukes to PCampbell for the idea of lock files.