cypher175 Posted November 5, 2008 Posted November 5, 2008 is there anyway to use the _Singleton() Function without specifying the exact process name in between the ("Brackets") So no matter what the script.exe is named only 1 Instance of it can run at a time..??
dbzfanatic Posted November 5, 2008 Posted November 5, 2008 If it's your script you can use If _Singleton(@scriptname) = 0 Then MsgBox(0,"Error","The script is already running.") Exit Endif Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
cypher175 Posted November 5, 2008 Author Posted November 5, 2008 If it's your script you can use If _Singleton(@scriptname) = 0 Then MsgBox(0,"Error","The script is already running.") Exit Endif thank you..
PsaltyDS Posted November 5, 2008 Posted November 5, 2008 If it's your script you can use If _Singleton(@scriptname) = 0 Then MsgBox(0,"Error","The script is already running.") Exit Endif The macro @ScriptName will be interpreted at compile time. If you compile again with a different script name (i.e. MyScript_v1.au3 and MyScript_v2.au3) then it will not recognize an instance of the other version. The string you provide _Singleton() can be as much as you need to uniquely identify the script: If _Singleton("MyTestScriptWhichMustOnlyHaveOneRunningInstance_0123_4567_89AB_CDEF") = 0 Then MsgBox(0,"Error","The script is already running.") Exit Endif 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
cypher175 Posted November 6, 2008 Author Posted November 6, 2008 @ PsaltyDS I not really sure what you are concluding..?? Are you say that all i rally need to do is just use _Singleton() just like that with no name inside the brackets or what exactly are you saying to do..??
rasim Posted November 6, 2008 Posted November 6, 2008 cypher175Singleton using Mutex object:Dim $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", False, "str", "MyProgramUniqueName") If $hMutex[0] Then MsgBox(64, "MyProgram", "Program is already running") Exit EndIf DllCall("kernel32.dll", "hwnd", "CreateMutex", "int", 0, "int", False, "str", "MyProgramUniqueName")
trancexx Posted November 6, 2008 Posted November 6, 2008 (edited) @ PsaltyDSI not really sure what you are concluding..??Are you say that all i rally need to do is just use _Singleton() just like that with no name inside the brackets or what exactly are you saying to do..??May I?He's saying that you shouldn't use @ScriptName because that can be changed (by you or whoever working with you on some project when making new versions of it, for example).Use "solid" string for that purposes. I would suggest generating GUID, but I guess "MyTestScriptWhichMustOnlyHaveOneRunningInstance_0123_4567_89AB_CDEF" is fine too. Edited November 6, 2008 by trancexx ♡♡♡ . eMyvnE
PsaltyDS Posted November 6, 2008 Posted November 6, 2008 cypher175 Singleton using Mutex object: Dim $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", False, "str", "MyProgramUniqueName") If $hMutex[0] Then MsgBox(64, "MyProgram", "Program is already running") Exit EndIf DllCall("kernel32.dll", "hwnd", "CreateMutex", "int", 0, "int", False, "str", "MyProgramUniqueName") That's how _Singleton() already works. Check the code for it inside the Misc.au3 UDF. May I? He's saying that you shouldn't use @ScriptName because that can be changed (by you or whoever working with you on some project when making new versions of it, for example). Use "solid" string for that purposes. I would suggest generating GUID, but I guess "MyTestScriptWhichMustOnlyHaveOneRunningInstance_0123_4567_89AB_CDEF" is fine too. Exactly right. The string I provided was meant to be a little over the top and therefore mildly humorous, but nobody ever seems to find the same things funny that I do... 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
trancexx Posted November 6, 2008 Posted November 6, 2008 I would like to express strong disagreement with some parts of the last post here (prior this one). I had few laughs (that person related) here lately. ♡♡♡ . eMyvnE
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