Jump to content
Sign in to follow this  
JonnyThunder

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?

Share this post


Link to post
Share on other sites

Yeah, there is - but I want to check if the script is already running (on startup) so that I can exit the script if an instance is found. I know there's a simple way to do it - I read it here before. Just can't find it again.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

Once again, thank you.

It seems i'm in 'schoolboy error hell' today.

:)

No problem. That's what we are here for :)


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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...