In a word.. ugh!

Using files to track system processes is like herding cats - possible, but you don't really want to.

I'll dig up some code I have and post it in a bit, but here's something to consider:

  • Use a process-list UDF to determine how many processes are running
  • If the number of processes is 0 or 1, allow the new process to start
  • If the number of processes is 2, display a warning and exit
  • No file cleanup, no mess if the ap terminates abnormally, and totally dynamic
I have an application that allows up to 25 sub-processes to run to communicate with remote systems. Any number of the 160+ servers can requests service, but only 25 at a time are allowed to run. I take it a step further and correlate which process is used to communicate with which server, and check every few seconds to see if a process has ended. If it is no longer in the list, I perform some wrap-up, and allow another process to start if any are in the queue. It sounds like what you want to do is 23 times simpler. ;\)
 Code:
$aProcessList = WMIProcessList('appname')
If UBound($aProcessList) < 1
  Run 'app.exe args'
Else
  'Sorry - can only run two instances of "appname"!' @CRLF
EndIf
is really about all you'd need.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D