roofninja Posted February 28, 2011 Posted February 28, 2011 How do I stop the program from being run more than once? Like I double clicked it and I thought that it didn't run, so I double clicked it again. I would like the program to not run again. Sorry for a repeat, but I didn't see anything about this. RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!
martin Posted February 28, 2011 Posted February 28, 2011 How do I stop the program from being run more than once? Like I double clicked it and I thought that it didn't run, so I double clicked it again. I would like the program to not run again.Sorry for a repeat, but I didn't see anything about this.Look up _Singleton. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
roofninja Posted February 28, 2011 Author Posted February 28, 2011 Thanks, I didn't know that this has been included. Thanks. RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!
bo8ster Posted March 1, 2011 Posted March 1, 2011 Use #include <Misc.au3> ; #FUNCTION# ==================================================================================================================== ; Name...........: _Singleton ; Description ...: Enforce a design paradigm where only one instance of the script may be running. ; Syntax.........: _Singleton($sOccurenceName[, $iFlag = 0]) ; Parameters ....: $sOccurenceName - String to identify the occurrence of the script. This string may not contain the \ character unless you are placing the object in a namespace (See Remarks). ; $iFlag - Behavior options. ; |0 - Exit the script with the exit code -1 if another instance already exists. ; |1 - Return from the function without exiting the script. ; |2 - Allow the object to be accessed by anybody in the system. This is useful if specifying a "Global\" object in a multi-user environment. ; Return values .: Success - The handle to the object used for synchronization (a mutex). ; Failure - 0 ; Author ........: Valik ; Modified.......: ; Remarks .......: You can place the object in a namespace by prefixing your object name with either "Global\" or "Local\". "Global\" objects combined with the flag 2 are useful in multi-user environments. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
Shaarad Posted March 4, 2011 Posted March 4, 2011 (edited) If you don't want to use _singleton, there's another way, at the beginning of the code , add a regread to check for a particular key value in registry. if it is not there, then use regwrite to write that key value in the registry, and in the end use regdelete to delete that value. so, when the program starts, it will try to read a particular value (i.e., to check whether another instance of program is running or not,) if that key value doesn't exist, then it will make one and keep the other instances out of its way. Also, deleting the key at the end of execution will enable the program the new instance to run... Edited March 4, 2011 by Shaarad 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.
hannes08 Posted March 4, 2011 Posted March 4, 2011 Hi Shaarad, if the program terminates before you can perform your regdelete then you (or a user) will never be able to run the program again. I think _Singleton is a better solution. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Shaarad Posted March 7, 2011 Posted March 7, 2011 Hi Shaarad,if the program terminates before you can perform your regdelete then you (or a user) will never be able to run the program again. I think _Singleton is a better solution.yup...correct..I just wanted to give another solution.. 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.
Cybergraph Posted March 7, 2011 Posted March 7, 2011 (edited) This is another way (place this code at the start of the script): Dim $Process_exists $list = ProcessList(@ScriptName) for $i = 1 to $list[0][0] $Process_exists = $Process_exists + 1 next If $Process_exists > 1 Then Exit EndIf Edited March 7, 2011 by Cybergraph
bo8ster Posted March 8, 2011 Posted March 8, 2011 Singleton is a design patten, you can implement it many different ways it its still a Singleton by definition. AutoIt provides the _Singleton function which is probably the best way to implement the pattern in AutoIt, I don't understand why you wouldn't use it. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
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