Jump to content
Sign in to follow this  
david1337

Only 1 instance of my script

Recommended Posts

Hi guys

 

If I have a script named "test.exe" running, and while it's running the script "test.exe" will run a new instance, how can I make sure that the second instance waits for the existing instance to finish?

I guess that I should use _Singleton ? But I can only find examples that kills the second instance, instead of waiting for the existing instance, and then run.

Thanks!

David

Share this post


Link to post
Share on other sites

You can add this kind of code at the begining of your script :

While ProcessList(@ScriptName)[0][0] > 1
WEnd

; And then your code...
MsgBox(0, "", "Hello")

Compile and run it twice, you will see the 2nd script waits until the first one does not exist

Share this post


Link to post
Share on other sites
#include <_SingleScript.au3> ;https://www.autoitscript.com/forum/topic/178681-_singlescript-assure-that-only-one-script-with-the-same-name-is-running

_SingleScript(1)

MsgBox(64+262144, Default, "Press OK to exit",0)

This one checks for au3 and exe

Edited by Exit
point to new #include location

UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


Link to post
Share on other sites

Nice one jguinch that's much simpler, I just spent a couple of minutes trying to figure this out.

While 3
    $aList = ProcessList("Test.exe")
    If $aList[0][0] = 0 Then ExitLoop
    If $aList[0][0] > 1 Then
        Sleep(333)
        ContinueLoop
    Else
        ExitLoop
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...