PGTART Posted September 10, 2013 Share Posted September 10, 2013 I made a script that does work nice it does do all kind of stuff However it gets into problems, when the script is double clicked and executed twice. I need to make sure only whan script can run at a time, how can i achieve that ? Link to comment Share on other sites More sharing options...
michaelslamet Posted September 10, 2013 Share Posted September 10, 2013 Pgtart, check _Singleton function and example Link to comment Share on other sites More sharing options...
Solution Morthawt Posted September 10, 2013 Solution Share Posted September 10, 2013 (edited) In the help file look up the function _Singleton http://www.autoitscript.com/autoit3/docs/libfunctions/_Singleton.htm Edited September 10, 2013 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
careca Posted September 10, 2013 Share Posted September 10, 2013 If that doesn't work, maybe try to write to a ini, say, its running write running = 1, and when it starts, search that, if 1, exit, without changes, the first/original script writes 0 uppon close. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
BrewManNH Posted September 10, 2013 Share Posted September 10, 2013 _Singleton is a safer approach. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
TheSaint Posted September 11, 2013 Share Posted September 11, 2013 @careca - that's a very odd thing to say. What do you think _Singleton was designed for? If it didn't work, it would be highly likely the user's fault. Better to get it right in that instance, than muck around using alternatives not as good. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
careca Posted September 11, 2013 Share Posted September 11, 2013 I Agree, TheSaint, that was not the right sentence right there. I meant something along the lines of, "if you want, as an alternative." Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Celtic88 Posted September 11, 2013 Share Posted September 11, 2013 __MUTEX() MsgBox(0, '','') Func __MUTEX($SEMAPHORE = "Autoit_a") Local $ERROR_ALREADY_EXISTS = 183 DllCall("kernel32.dll", "int", "CreateSemaphore", "int", 0, "long", 1, "long", 1, "str", $SEMAPHORE) Local $LASTERROR = DllCall("kernel32.dll", "int", "GetLastError") If $LASTERROR[0] = $ERROR_ALREADY_EXISTS Then Exit EndFunc ;==>__MUTEX Link to comment Share on other sites More sharing options...
TheSaint Posted September 11, 2013 Share Posted September 11, 2013 @Mrbenkali - very nice, but hardly needed compared to the much simpler _Simpleton, and it could do with some explanation. Is "Autoit_a" the program name or what? I'm presuming it would need to be a more unique indicator. That may even be the same code that _Simpleton uses? Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 11, 2013 Share Posted September 11, 2013 (edited) That may even be the same code that _Singleton uses? In accordance to my opinion Semaphore can be preferred over Mutex for avoiding duplication of a process, sincea mutex is costly operation due to protection protocols associated with it. Though a Semaphore could be unlocked by another process, it could be ignored for our case. More Information Difference : Semaphore and Mutex Edited September 11, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
BrewManNH Posted September 11, 2013 Share Posted September 11, 2013 Using a mutex means that the lock won't be unlocked until the calling process closes or unlocks it, whereas a semaphore can be unlocked by any process. Seeing as how the OP asked for a lock, I'd use a mutex. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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