Using a file will work most of the time, unless:
1. Your program crashes and doesn't remove the file on exit - your program won't run at all until you remove the file.
2. Both exe's test for the file at the same time - two copies of your program run.
You need to use an atomic operation as John Y said.
Luckily, there's a way to do this using system level mutexes, and I've got those included in my utility plug-ins:
+ Code Snippetmake sysobj mutex 1, "MyGame"
if try lock sysobj(1) = 0 then end
wait key
The first line creates a named mutex. The second line attempts to get a unique lock on the mutex. If the TRY LOCK SYSOBJ function returns a 1 it got the lock and it's the first occurrence of your progra,. If it returns a 0, it didn't and is the second or later occurrence of your program.
When the program ends it will automatically release the lock.
Make sure you use a name that is unique to your program - the best way is to generate a GUID. There's a function GENERATE GUID$ in my string plug-in that will generate a unique string every time you run it - use the following code in a standalone program to generate a GUID and put it into the clipboard for this purpose: