oholdeno Posted September 22, 2005 Share Posted September 22, 2005 i've compiled a script into an executable. it's working great. the only thing i'd like to fix is to somehow have it only run once instance of it at any time. running multiple instances will mess up how the program works. can anyone help me out? Link to comment Share on other sites More sharing options...
Valuater Posted September 22, 2005 Share Posted September 22, 2005 i've compiled a script into an executable. it's working great. the only thing i'd like to fix is to somehow have it only run once instance of it at any time. running multiple instances will mess up how the program works. can anyone help me out?one of the top questions in the FAQ's14. How can I make sure only one copy of my script is run?The easiest way is to rename the title of the hidden AutoIt window when your script first starts. Then in the same script check for that window title existing - if it does then another copy of the script is running.; Place at the top of your script$g_szVersion = "My Script 1.1"If WinExists($g_szVersion) Then Exit ; It's already runningAutoItWinSetTitle($g_szVersion); Rest of your script goes here Back To Top8) Link to comment Share on other sites More sharing options...
jpm Posted September 22, 2005 Share Posted September 22, 2005 i've compiled a script into an executable. it's working great. the only thing i'd like to fix is to somehow have it only run once instance of it at any time. running multiple instances will mess up how the program works. can anyone help me out?see _Singleton UDF functions Link to comment Share on other sites More sharing options...
Danny35d Posted September 22, 2005 Share Posted September 22, 2005 I used this line right after all my #includeIf UBound(ProcessList(@ScriptName)) > 2 Then ExitIt only allow one instance of a script running.... AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
VicTT Posted September 22, 2005 Share Posted September 22, 2005 Danny35d --> That's a really NEAT snippet..It took me a 30 second ponder to understand how it works, but REALLY neat ..Keep up the good work Quote Together we might liveDivided we must fall  Link to comment Share on other sites More sharing options...
Valik Posted September 22, 2005 Share Posted September 22, 2005 I used this line right after all my #includeIf UBound(ProcessList(@ScriptName)) > 2 Then ExitIt only allow one instance of a script running....No, all that does is disallows one named instance of the same copy of a script to be running. If I copy/rename your script while it's already running, I can start a second instance. Relying on something dynamic for your singleton pattern enforcement is a recipe for disaster because dynamic things can change (Funny how that works, no?). Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 22, 2005 Moderators Share Posted September 22, 2005 This gives 2 other alternatives of what the masses of the group here have put, but more importantly it gives the correct Semaphore that Valik is talking about.The first example is Valiks correct one, the 2nd is my attempt to make sure it got the correct file.Semaphore vs. File Search 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 More sharing options...
Valik Posted September 22, 2005 Share Posted September 22, 2005 This gives 2 other alternatives of what the masses of the group here have put, but more importantly it gives the correct Semaphore that Valik is talking about.The first example is Valiks correct one, the 2nd is my attempt to make sure it got the correct file.Semaphore vs. File SearchYour second example is inherently flawed as well. What happens if for some reason I have a binary already running with the same name as your script but it's not your script? In that case, I won't be able to start any instance.Any time you try to base a singleton pattern around some dynamic object, it is no longer a singleton. The checked object has to be immutable, otherwise, it will be possible to circumvent the singleton checks and get two instances. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now