Preventing multiple instances of a Windows app - still a problem
livfoss at mac.com
Sun Dec 4 18:24:16 EST 2011
Thanks to all those who replied to my query - I appreciate both the speed and the enthusiasm of the replies! So far I have not succeeded, but I am more than ready to believe that it's finger-trouble on my part.
To take Mark Schonewille's suggestions first:
1. As I stated in my original post, I am trying to prevent multiple instances of a non-LC application, so thanks but sadly 'relaunch' won't touch the problem as far as I can see - I think 'relaunch' is actually implemented as a LC engine (or inter-engine) activity.
2. Also sadly you are right and 'tasklist' is not available in Windows XP Home, which I am using and which I'm certain a good many of my users will be using too. When I do
'tasklist' is not recognized as an internal or external command, operable program or batch file.
Next, Thierry Douez:
> Did you tried this way:
> get "tasklist /NH /FI " & quote & "IMAGENAME eq firefox.exe" & quote
> put shell( IT )
> -- or process the shell() output
> get "tasklist /NH /FI " & quote & "IMAGENAME eq Troubling\ App.exe" &
> put shell( IT )
> Solution 1, I'm sure it works
> Solution 2, didn't test it.
Same problem - can't access 'tasklist'. And actually I don't understand what this script does. Presumably the parameters NH and FI do the killing?
Next, Mike Bonner - again can't use tasklist, but there is a glimmer of hope in your remark
> Since you just want to kill the process, and not necessarily bring it to
> the front or anything like that, I think this is great advice. Just kill it
> through shell, shouldn't matter if its actually running or not.
Can I kill the process without using 'tasklist'? Since I apparently don't need to know if the process is in the list or not, could I go direct to 'kill' or whatever it's called in Windows? I tried
put shell("kill FireFox.exe") but it seems 'kill' wasn't recognised, nor was 'pskill' - I have a list of Windows Command-line commands via Google in which these are included but it seems that my 'shell' doesn't invoke them.
Finally, Mike gave me this little script in May - I tried to put it in a field and 'do' it as vbscript. Didn't works so then I put it in a text file, read it and tried do as vbscript again. Both times I got an execution error. Maybe it's just too late at night…
'sets the environment
Set WshShell = WScript.CreateObject ("WScript.Shell")
'grabs the full processlist and puts it in a var
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from
'loops through each looking for a match
For Each objProcess in colProcessList
If objProcess.name = "firefox.exe" then
'sets a flag if a match is found
vFound = True
'next loop of course
'if a match was found, activate the app
If vFound = True then
' otherwise, run the app
More information about the Use-livecode