How to prevent multiple instances of a non-LC Windows app?

Mike Bonner bonnmike at gmail.com
Fri May 20 09:50:34 EDT 2011


I couldn't get it to work straight from a field, had the same problem.  I
suspect, getting quotes and environment correct in the script itself is a
large part of the problem, but I just couldn't find the right combination
which is why I did it as a file.

Instead you might store the script in a propterty, then make a file in the
windows temp folder that you can run. This way you don't have to bundle a
seperate file with your app, but can still make it work.  (assuming the
windows scripting host is a similar enough version that it will work)

On windows you can set the defaultfolder to specialfolderpath("Temporary")

then put the contents of your property into a file there.
put the cScript of this stack into URL "file:myTmp.vbs"
shell("myTmp.vbs")



On Fri, May 20, 2011 at 6:40 AM, Graham Samuel <livfoss at mac.com> wrote:

> Correction - in the real VB script I had not forgotten the quote before the
> first instance of 'firefox.exe' in the script below. Just a transcription
> error. The actual script that fails has the line
>
> If objProcess.name = "firefox.exe" then
>
> Sorry for that
>
> Graham
>
> ========
> Thanks to all who replied to this and my other queries about "tasklist" on
> Windows (not available on the basic version of XP that most of my users are
> running). Basically there does seem to be a bug in the LC 'launch' command,
> and I will report it. Meanwhile I am trying to follow Mike Bonner's advice
> as shown in the quote below. As I didn't want to use a separate file, I put
> this (VB) script into a field called "VBScript" in a test stack:
>
> Set WshShell = WScript.CreateObject ("WScript.Shell")
> Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from
> Win32_Process")
>
>
> For Each objProcess in colProcessList
> If objProcess.name = firefox.exe" then
> vFound = True
> End if
> Next
> If vFound = True then
> WshShell.AppActivate "firefox"
> Else
> WshShell.Run "firefox.exe"
> End If
>
> Following Mike, I'm just using FireFox as a test program - in the end I
> will use the particular program I'm interested in.
>
> I then run this LC script from a button of my program which has been
> compiled as a Windows standalone:
>
> local scriptName
> on mouseUp
>   put "VBScript" into scriptName
>   do fld "VBScript" as scriptName
>   answer "Result is:"&&(the result)
> end mouseUp
>
> (BTW I found that using the word 'VBScript' directly results in a compile
> error, even tho VBScript is in the list of alternateLanguages - dunno why).
>
> Anyway the result is 'execution error'.
>
> As I know zilch about VB I am stuck  - can anyone suggest what I should
> have done? Do I **have** to use 'shell' - I am reluctant because it takes me
> more into unknown regions.
>
> Finally, I should say that I do have a copy of FireFox on the PC, although
> I find that Windows Explorer doesn't show the '.exe' at the end of its name.
> So a subsidiary question is, how can I know exactly what Windows thinks the
> entire name of my particular executable program is, particularly if there's
> a space in the name (eg. "My Program" - does that get called as "My
> Program.exe" or what?)
>
> TIA
>
> Graham
>
> On Wed, 18 May 2011 15:39:13 -0600, Mike Bonner <bonnmike at gmail.com>
> wrote:
>
> > I can't test with win xp, but you might put the following into a .vbs
> file.
> >
> > *Set WshShell = WScript.CreateObject ("WScript.Shell")*
> > *Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from
> > Win32_Process")*
> > *
> > *
> > *For Each objProcess in colProcessList*
> > *If objProcess.name = "firefox.exe" then*
> > *vFound = True*
> > *End if*
> > *Next*
> > *If vFound = True then*
> > *WshShell.AppActivate "Firefox"*
> > *Else*
> > *WshShell.Run "Firefox.exe"*
> > *End If *
> >
> > In my example, it will check for firefox, if its running it will focus on
> > it, if not it will start a new instance.  To use it, do a shell call.
> >
> > get shell("myScript.vbs")
> >
> > I'm sure it could be easily modified so you could pass it the program to
> > find as a parameter, but if its always the same hard coded should be
> fine.
> >
> > Got the script from here.
> > http://www.tek-tips.com/viewthread.cfm?qid=1492889&page=6 and changed it
> > slightly.
> >
> > Hope it works on xp home, works fine on 7.
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list