Jump to content
Sign in to follow this  
Dryden

Detect a second instance runing

Recommended Posts

Dryden

Hi.

My script is very complex, and I'm trying to keet the error margin to the minimum, but I have a problem.

The script alows multiple instances, and that causes instability cos they all work under the same base but not all at the same time.

Resuming, if I or someone opens more than one instance of my script you better take cover co's the computer is going to BOOM! ;)

So what I wanted was a simple way to prevent multiple executions.

I tried simething simple like:

If ProcessExists("k-auto.exe") Then
    While ProcessExists("k-auto.exe")
    MsgBox(16,$prog,"Já está a correr uma instância do programa. A Sair"& @CRLF & " " & @CRLF &"Clique OK ou espere 5 segundos.",5)
    Exit
EndIf

The problem is that with this way it doesn't start even the first time...

So I thought that since I already use an .ini file I could make a field saying something like:

ScriptRunning=0 or

ScriptRunning=1

So i make the script run that it checks for ScriptRunning if it is 0 it runs and it changes it to 1, if ScriptRunning is 1 thet it doesn't run. And when I exit the script it changes ScriptRunning back to 0. But this has 2 major flaws.

1st is very easy for someone to change a .ini file

2nd if the computer shuts down or resets without closing the script correctly for some reason, next time it boots up the script won't run cos ScriptRunning is still = 1.

Any thoughts on this?

Edit:

Ah! and I'm also looking for a way to prevent people from changing the .exe name.

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
Dryden

http://www.autoitscript.com/forum/index.php?showtopic=37289

Question 3 :D

Try a search next time before posting ;)

#include <Misc.au3>
If _Singleton("MyScriptName", 1) Then
   ; We know the script is already running. Let the user know.
    MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")
    Exit
Endif

this doesn't work for me either... It doesn't open at all... I allways get the msgbox


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
LongBowNZ

Edit:

Ah! and I'm also looking for a way to prevent people from changing the .exe name.

Maybe (Not Tested):

If @Compiled Then 
    If Not @ScriptName = 'Name of exe.exe' Then 
        MsgBox(0, 'Error', 'Exe is meant to be named "Name of exe.exe" Rename it back to original name to run.')
        Exit
    EndIf
EndIf

#include <Misc.au3>
If _Singleton("MyScriptName", 1) Then
  ; We know the script is already running. Let the user know.
    MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")
    Exit
Endif

this doesn't work for me either... It doesn't open at all... I allways get the msgbox

Try this:

#include <Misc.au3>
If _Singleton("MyScriptName", 1) = 0 Then
  ; We know the script is already running. Let the user know.
    MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")
    Exit
Endif
Edited by LongBowNZ

Share this post


Link to post
Share on other sites
Dryden

Maybe (Not Tested):

If @Compiled Then 
    If Not @ScriptName = 'Name of exe.exe' Then 
        MsgBox(0, 'Error', 'Exe is meant to be named "Name of exe.exe" Rename it back to original name to run.')
        Exit
    EndIf
EndIf

Try this:

#include <Misc.au3>
If _Singleton("MyScriptName", 1) = 0 Then
 ; We know the script is already running. Let the user know.
    MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")
    Exit
Endif
thx m8, the second instance detection works perfect. ;)

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

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  

×