Preventing multiple instances of a Windows app - still a problem
livfoss at mac.com
Sun Dec 4 06:53:37 CST 2011
Those with long memories may recall that last May (!) I was looking for a solution to the following problem:
In a Windows environment, I have a LiveCode app that sometimes is required to launch another, non-LC, app and then quit. This is quite easy to accomplish with LC's 'launch' command, and rather pleasingly, the 'quit' still goes on working when the new app comes to the foreground. However a problem can arise if my user does this trick more than once without exiting the non-LC program (let's call it 'Troubling App'). This is because the 'launch' command doesn't check for an existing instance of Troubling App, but just happily launches a second instance (and in principle, a third, fourth etc). The LC dictionary leads one to believe that one can detect the presence of a second instance, but this isn't true - this only applies, if at all, to LC-originated executables.
Last May I got lots of good advice from this list (specially from Mike Bonner) about how to deal with this problem, and it came down to running a little VB script that ran through the open processes on the machine and killed any duplicate of the program in question: this is not the absolutely ideal solution, which would be to tell the LiveCode script that an instance already exists so that the launch won't be needed, but it is workable. Except for one show-stopper: in the example above I chose 'Troubling App' as a name, **because it has a space in it**. It turns out the VB script I was given worked fine for 'Firefox' for example, but didn't work for any program name with a space in it - this despite my enclosing the statement referring to the program in quotes, as in:
If objProcess.name = "Troubling App.exe" then
I never got past this obstacle, and stopped thinking about it - but now it's come back to bite me again. Can anyone explain what I should do - maybe it's as simple as representing the program name in another way?
PS Just in case you're wondering, I can't change the name of the program in question, as it already has around 10000 users.
More information about the use-livecode