Jump to content

Check if program is running already


Recommended Posts

Hello,

I saw this already - but a search didn't show it up. How can I check if the current script is already running so that I don't have two instances of the same script running on a PC?

If you look at the Misc.au3 UDF there is a function called _Singleton that does just that.

Example:

If _Singleton($sOccurenceName, 1) = 0 Then
       MsgBox(16, "Error", Another instance of this program is already running.")
    Exit
EndIf

You can just type in _Signleton in the index portion of the helpfile and it will also tell you how to use it.

(Sorry in the middle of me typing this post I see that someone else has posted this. Sorry for the repeat.)

Edited by MattWise

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

I can't actually get _Singleton to work. It says the script is already running even for the first instance.

Am I right in saying that if I compile my script as "test.exe" then I should be using this....

If _Singleton("test.exe", 1) Then
    MsgBox(0, "Error", "Script is already running")
    Exit
Endif

That isn't working for me.

Link to comment
Share on other sites

Should be:

If _Singleton("test.exe", 1) = 0 Then
    MsgBox(0, "Error", "Script is already running")
    Exit
Endif

Your checking to see if it equals true, you should check to see if it equals false.

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...