Kurtferro Posted December 5, 2007 Share Posted December 5, 2007 Q3. How can I prevent more than one copy of my script from running at once / detect another copy of my script running? If you simply want know if another copy is running, you can use code similar to the next example: CODE: AutoIt #include <Misc.au3> If _Singleton("MyScriptName", 1) Then ; We know the script is already running. Let the user know. MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!") Exit Endif I have tried it but for me dont work. I need a singol istance. My script name is "ServerPorter" Link to comment Share on other sites More sharing options...
themax90 Posted December 5, 2007 Share Posted December 5, 2007 #Include <Misc.au3> _Singleton("ServerPorter", 0) Putting this at the top of the script will detect when opened if another copy is open and Exit upon finding it. Link to comment Share on other sites More sharing options...
Kurtferro Posted December 5, 2007 Author Share Posted December 5, 2007 I have already tried in all mode, but it never work with me, can be a problem with vista? i have made this function: Func CheckPID() $list = ProcessList("ServerPorter.exe") for $i = 1 to $list[0][0] if $list[$i][1] <> @AutoItPID then msgbox(4096, $list[$i][0], "ServerPorter.exe is already executed!!") Sleep(5000) exit 0 EndIf next EndFunc Link to comment Share on other sites More sharing options...
SpookMeister Posted December 5, 2007 Share Posted December 5, 2007 (edited) This is another example of how to do that from the help file (FAQ section); 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 hereTry it out Edited December 5, 2007 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Kurtferro Posted December 5, 2007 Author Share Posted December 5, 2007 K, it a solution, mine work too, but the problem is why _Singleton dont work? is my problem or is a bug? someone can try it and report the OS used? Link to comment Share on other sites More sharing options...
picaxe Posted December 6, 2007 Share Posted December 6, 2007 I use _Singleton on a few scripts with no problems, including _Singleton(@scriptname, 1). I am runing XP SP2. Link to comment Share on other sites More sharing options...
schilbiz Posted December 6, 2007 Share Posted December 6, 2007 I have already tried in all mode, but it never work with me, can be a problem with vista? i have made this function: Func CheckPID() $list = ProcessList("ServerPorter.exe") for $i = 1 to $list[0][0] if $list[$i][1] <> @AutoItPID then msgbox(4096, $list[$i][0], "ServerPorter.exe is already executed!!") Sleep(5000) exit 0 EndIf next EndFunc If your running Vista it doesn't hurt to put #RequireAdmin at the top of your code. Whenever I am making scripts that will be ran on a Vista system I just automatically put it in, it has made some work that should have otherwise been fine but wouldn't work. Vista's security is a hassle for admins as well as many other things. #RequireAdmin Link to comment Share on other sites More sharing options...
Kurtferro Posted December 6, 2007 Author Share Posted December 6, 2007 i will try, but my UAC is disabled. 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