Jump to content
Sign in to follow this  
AustrianOak

Program single instance

Recommended Posts

AustrianOak

What is the function or what will make my script run only once at a time. I know the code for this in autohotkey is #SingleInstance...

Thanks in advance,..

Share this post


Link to post
Share on other sites
SinkoDemio

_SingleTon(@ScriptName)

Share this post


Link to post
Share on other sites
danielkza

_SingleTon(@ScriptName)

I don't think this will work because changing executable/script name will change the singleton identifier and allow a second instance.

Try using a fixed phrase.

Share this post


Link to post
Share on other sites
SmOke_N

I don't think this will work because changing executable/script name will change the singleton identifier and allow a second instance.

Try using a fixed phrase.

You can use any string as the singleton identifier.... I wouldn't use the executable name, just type in something like: _SingleTon("MyUniqueStringToOnlyRunThisOnce")

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
AustrianOak

what do you mean by a unique string?

Share this post


Link to post
Share on other sites
SmOke_N

what do you mean by a unique string?

I gave you an example of a "Unique" string, something you feel no other program would be using.

Edit:

You could even create a GUID to use with it, but you don't have to be so elaborate.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Vindicator209

_SingleTon(@ScriptName)

will work fine, I think ScriptName returns the name no matter what they change it to


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites
danielkza

_SingleTon(@ScriptName)

will work fine, I think ScriptName returns the name no matter what they change it to

From HelpFile:

Filename of the running script.

That means if you run the script,change it's name and run it again,the _Singleton strings will be different,and it will not detect the new instance.

You must use a fixed,literal,non-changing string,such as "My Program Singleton that never changes",to make sure no 'cheating' is possible.

Share this post


Link to post
Share on other sites
PsaltyDS

_SingleTon(@ScriptName)

will work fine, I think ScriptName returns the name no matter what they change it to

You are wrong and SmOke_N is right.

Compile this script as Test.exe:

#include <Misc.au3>
If _Singleton(@ScriptName, 1) Then 
    MsgBox(64, "Singleton", "Singleton")
Else
    MsgBox(16, "Not Singleton", "Not Singleton")
EndIf

Now copy Test.exe to Test_New.exe and then run them both... They both say singleton.

Repeat the experiment with this code:

#include <Misc.au3>
If _Singleton("MyUniqueStringToOnlyRunThisOnce", 1) Then 
    MsgBox(64, "Singleton", "Singleton")
Else
    MsgBox(16, "Not Singleton", "Not Singleton")
EndIf

Now the second instance reports "Not Singleton".

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×