plastix Posted March 17, 2006 Posted March 17, 2006 (edited) I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.TIA Edited March 17, 2006 by plastix
Moderators SmOke_N Posted March 17, 2006 Moderators Posted March 17, 2006 I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.TIA Look at _Singleton() in the Beta help file. 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.
CyberSlug Posted March 17, 2006 Posted March 17, 2006 Yes, _Singleton() is the recommend method.FAQ #14 has an alternative.... Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
seandisanti Posted March 17, 2006 Posted March 17, 2006 I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.TIA yeah _Singleton() for limiting the number of instanciated copies of your script, but it sounds like you should look into WinList() too, not necessarily for what you're wanting it for (because singleton will take care of that issue) but just so you know about it.
plastix Posted March 18, 2006 Author Posted March 18, 2006 many thanks cameronsdad & CyberSlug. both methods work nicely... i'll stick to the _Singleton() method... appreciate the heads up re: WinList() Thanks again
seandisanti Posted March 20, 2006 Posted March 20, 2006 many thanks cameronsdad & CyberSlug.both methods work nicely... i'll stick to the _Singleton() method... appreciate the heads up re: WinList()Thanks again no problem, always glad to help.
Moderators SmOke_N Posted March 20, 2006 Moderators Posted March 20, 2006 no problem, always glad to help.That's funny, I mentioned the _SingleTon() first... and I'm the only one that didn't get mentioned... (Finding rock to hide under)... 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.
seandisanti Posted March 20, 2006 Posted March 20, 2006 That's funny, I mentioned the _SingleTon() first... and I'm the only one that didn't get mentioned... (Finding rock to hide under)...i actually noticed that too, but didn't say anything about it. happy belated birthday, man. how was your present?
slightly_abnormal Posted March 20, 2006 Posted March 20, 2006 (edited) i actually noticed that too, but didn't say anything about it. happy belated birthday, man. how was your present? How can this close the first process and start a new process, like refreshing..? you know instead of closing itself if it's already open. if _Singleton("test\test",1) = 0 Then Exit EndIf Edited March 20, 2006 by slightly_abnormal
Moderators SmOke_N Posted March 20, 2006 Moderators Posted March 20, 2006 (edited) What do you mean close the 'first' process. This is made to close the same process trying to start itself. So the first instance is never closed, only any extra instances are closed.MHz, made a "restart" or "refresh" script last week.Edit:Example using MHz's code: http://www.autoitscript.com/forum/index.ph...ndpost&p=159442 Edited March 20, 2006 by SmOke_N 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.
seandisanti Posted March 20, 2006 Posted March 20, 2006 What do you mean close the 'first' process. This is made to close the same process trying to start itself. So the first instance is never closed, only any extra instances are closed. MHz, made a "restart" or "refresh" script last week. Edit: Example using MHz's code: http://www.autoitscript.com/forum/index.ph...ndpost&p=159442i think i would have to laugh if i get a thanks for this and you don't ron. If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf $Main = GUICreate("Example", 140, 60,-1, -1) $Button1 = GUICtrlCreateButton("Restart", 20, 10, 100, 40) GUISetState() While 1 $msg = GUIGetMsg() If $msg = - 3 Then Exit If $msg = $Button1 Then Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit EndIf WEnd
slightly_abnormal Posted March 20, 2006 Posted March 20, 2006 I mean, I have a script running, and then I start that same script it will close the script that was already running but keep the newly started one.. if _Singleton("test\test",1) = 0 Then Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') EndIf ???
slightly_abnormal Posted March 21, 2006 Posted March 21, 2006 I mean, I have a script running, and then I start that same script it will close the script that was already running but keep the newly started one.. if _Singleton("test\test",1) = 0 Then Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart')EndIf???causes it to reapear endlessly..
Moderators SmOke_N Posted March 21, 2006 Moderators Posted March 21, 2006 (edited) causes it to reapear endlessly.. You did "Compile" it first right? Edit: Actually now that I think about it, have you looked at the _SingleTon() UDF, it's preset to do something already...Try this code without _SingleTon()If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf ;Placing this outside the loop, so you can see it's only generated when the script starts Local $ShowTitle = '' For $x = 1 To 10 $ShowTitle = $ShowTitle & Chr(Random(65, 90, 1)) Next While 1 If UBound(ProcessList(@ScriptName)) > 2 Then If MsgBox(4, 'Restart', 'There was another instance, would you liket o restart?') == 6 Then Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit EndIf EndIf ToolTip('This EXE Self Title: ' & $ShowTitle, 0, 0) Sleep(10) WEndOnly Compile this code so you can see it working! Edit 2: Gave a better example... with the example above, the only way to change that title is with a new restart (you still need to compile it first). Watch as you try to open the .exe again, it will automatically restart and the title will change. Edited March 21, 2006 by SmOke_N 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.
Moderators SmOke_N Posted March 21, 2006 Moderators Posted March 21, 2006 Well since you were on most of the evening 'slightly_abnormal', did the above example work (I know it works) but more so solve your issue? 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.
slightly_abnormal Posted March 22, 2006 Posted March 22, 2006 Well since you were on most of the evening 'slightly_abnormal', did the above example work (I know it works) but more so solve your issue?yes, thanks. I forgot to reply.
jvanegmond Posted March 22, 2006 Posted March 22, 2006 This may be not entirely true On line 1 If ProcesExists("AutoIt3.exe") Then EXIT EndIf It unfortunately also checks if ANY other scripts are launched. github.com/jvanegmond
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