Progress on preventing multiple instances of a program from running in windows

Lynch, Jonathan BNZ2 at CDC.GOV
Thu Dec 2 14:50:14 EST 2004


Hello... the following script seems to work.

Factors to consider:
1)	The stack should be set to purge itself from memory upon closing
2)	Some firewalls might prevent the program from accepting
connections on a port
3)	This prevents multiple instances, but still does not quite allow
the two instances to communicate. Writing to a socket from one instance
seems to steal the ability of the other instance to listen to that
socket - I am still trying to work out how to do that.
4)	You might want to consider hiding the windows console and
setting the cursor to watch while the script performs the shell command.
5)	This will not work with the opensockets function, because that
does not return the sockets opened by the other instance. The shell
command for this works quite well (at least on my computer).

Cheers,
Jonathan


on preopenstack
  get shell("netstat -a")
  put it into OPS
  put the number of lines in OPS into Z
  set the itemdelimiter to ":"
  repeat with X = 1 to Z
    put word 2 of line X of OPS into WPS
    if item 2 of WPS = "48953" then put "open" into queryold
  end repeat
  if queryold = "open" then
    answer "This program is already running, do you wish to run another
instance of it?" with "No" and "Yes"
    put it into AAA
    if AAA = "No" then 
      close this stack
    end if
  else
    accept connections on port 48953 with message "queryinstance"
  end if
end preopenstack

on queryinstance skt
  -- to be used for further development
end queryinstance



More information about the use-livecode mailing list