Preventing multiple instances of a Windows app - still a problem

Mike Bonner bonnmike at gmail.com
Sun Dec 4 19:19:52 EST 2011


If running from within livecode (do "" as) all you get back if there is an
execution error is execution error. Not sure why it doesn't pop up a real
error dialog when running from a file.

The kill command on windows is taskkill. Its used in the other script you
sent to me, and vbscript just shells out to do the work.  I'm unsure if
taskkill is in xp home either though and have no way to test.

Also hope you don't mind me posting your 2nd script, but here goes.

Set WshShell = WScript.CreateObject ("WScript.Shell")
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from
Win32_Process")
'===========================================================
===================================
For Each objProcess in colProcessList
If objProcess.name = "Local Studies.exe" then
vFound = True
End if
Next
If vFound = True then
WshShell.Run ("C:\Windows\system32\cmd.exe")
WshShell.sendkeys "taskkill /IM Local Studies.exe" --Shell call to taskkill
WshShell.SendKeys "{ENTER}"
Else
Msgbox("Not Found")
End If

If taskkill works shelled out from vbs then you can most likely call it
directly from livecode.

Like all shell calls you'll need to build up the string so that it quotes
"Local Studies.exe"  to avoid any issues. In fact, it seems that the
vbscript might need to have Local Studies.exe quoted, or escaped to get it
to work.

Finally, if you decide you DO need to confirm whether or not your external
program is running, the 2 liner I posted earlier is a good way, and doesn't
require an external vbs file to work correctly.

Reposting it here so you can test on xp.

Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from
Win32_Process WHERE Name = 'Local Studies.exe'")
result = colProcessList.Count

This places the number of processes found that match in the result. If the
result is > 0 the process is running. Note the single quotes around the
process name.

If the result is > 0 then if taskkill.exe is present, kill the process. If
taskkill.exe isn't there, last resort could be to have the user shut the
program down themselves.

Oh, last thing, if you have trouble getting the "WHERE" clause to work as
far as finding your process name you can change it to "WHERE Name LIKE
"%Local Studies%" instead (% being wildcards)  Might make it easier.



More information about the use-livecode mailing list