traxxer Posted February 17, 2010 Posted February 17, 2010 (edited) Hi there We have an environment where we launch AU scripts via logon script, via RunOnce registry key or where different applications may start AU scripts. Of course, sometimes different AU scripts mess themselfes up when running simultaneously. How can I prevent an AU script from running, when another instance of AutoIt is already active? Thanks very much in advance! Michael ---- AutoIt v3.3.0.0 / WinXP SP3 Edited February 17, 2010 by traxxer
99ojo Posted February 17, 2010 Posted February 17, 2010 (edited) Hi, if you have compiled exe files, store them in a text file -> maybe on your netlogon share. e.g. proclist.txt: mapdrive.exe checkgroup.exe Use _FileReadToArray to store the exe files into an array. Then loop over array and check with ProcessExist (<arrayelement>) if the process exists. If yes, exit your script. #include <file.au3> _checkproc () Func _checkproc () Local $arprocess Local $logonsvr = EnvGet ("logonserver") Local $procfile = $logonsvr & "\netlogon\proclist.txt" _FileReadToArray ($procfile, $arprocess) For $i = 1 To UBound ($arprocess) - 1 If StringInStr ($arprocess [$i], @Scriptname) Then ContinueLoop If ProcessExists ($arprocess [$i]) Then Exit Next EndFunc ;-)) Stefan @Edit: Insert If StringInStr ($arprocess [$i], @Scriptname) Then ContinueLoop to prevent script from closing itself. If you want to wait until a running process ends: #include <file.au3> _checkproc () Func _checkproc () Local $arprocess Local $logonsvr = EnvGet ("logonserver") Local $procfile = $logonsvr & "\netlogon\proclist.txt" _FileReadToArray ($procfile, $arprocess) For $i = 1 To UBound ($arprocess) - 1 If StringInStr ($arprocess [$i], @Scriptname) Then ContinueLoop If ProcessExists ($arprocess [$i]) Then $pid = ProcessExists ($arprocess [$i]) While $pid <> 0 sleep (100) ; to reduce CPU $pid = ProcessExists ($arprocess [$i]) WEnd ;_checkproc () ;you may use recursive level, but be careful because of recursive level restrictions EndIf Next EndFunc Edited February 17, 2010 by 99ojo
hot202 Posted February 17, 2010 Posted February 17, 2010 Do you mean that u dont want the same scrit to run if it is already running? If so this is what u need, Put it at the top of your scripts. #include <Misc.au3> if _Singleton("test",1) = 0 Then Msgbox(0,"Warning","An occurence of test is already running") Exit EndIf Msgbox(0,"OK","the first occurence of test is running")
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