Jump to content

Program single instance


Recommended Posts

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

_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]

Link to comment
Share on other sites

_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.

Link to comment
Share on other sites

_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
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...