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

Mike Bonner bonnmike at gmail.com
Fri May 20 09:59:42 EDT 2011


The reason the exe doesn't show in windows explorer is because there is a
setting to hide known extensions.

If you want to see this behavior changed, in windows explorer, click tools,
either options or folder options (doing this from memory, don't have xp
anymore) click the view tab and you get a long list of checkboxes.
Relatively near the top are several interesting ones. One that hides certain
extensions, another that will toggle the option to show or hide hidden and
system files and a box to display the full path in the title bar.  I usually
set all these to show for me, but for most other people I leave the "show
hidden files, folders and drives" radio button set to hide simply so its
harder to have an accidental system nuke.

There is a way in vbs to do a less explicit match, I think you can do a find
instead but I'm just learning about vbs myself.  (Seems pretty handy
sometimes though, so probably worth the effort)

Out of curiosity, did you try the test with firefox (making a file,
executing it by hand) to make sure it will actually work with xp?  I don't
know how many changes there are if any between the xp script host, and win7.

On Fri, May 20, 2011 at 7:50 AM, Mike Bonner <bonnmike at gmail.com> wrote:

> 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