Juvigy Posted October 21, 2013 Share Posted October 21, 2013 Hi Guys, I have a Outlook rule that runs exe file created with Autoit. The problem is that if the exe is already running and a new instance is started , the new instance should wait for the first one to finish. How can i accomplish that ? While _Singleton("s111.exe",1) = 0 Msgbox(0,"Warning","An occurence of S111.exe is already running",10) WEnd This one works for 2 exe files , but if there are more it stucks as the loop condition is always true. Also the exe files ideally should be proceeded in the order they have been started. Any easy way to do this ? Link to comment Share on other sites More sharing options...
czardas Posted October 21, 2013 Share Posted October 21, 2013 You might get some ideas from looking at my >win-1252 extended ascii keyboard. It will only display properly if your codepage is win-1252. In any case, try running it twice and see what happens. Particularly look at the function _IsRunning(). Look in the help file for WinWaitClose, WinExists etc... operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
guinness Posted October 21, 2013 Share Posted October 21, 2013 What's _IsRunning()? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
czardas Posted October 21, 2013 Share Posted October 21, 2013 What's _IsRunning()? It's a function in my script guinness - what else? operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Juvigy Posted October 21, 2013 Author Share Posted October 21, 2013 I checked it - i cant use Win functions as my program doestn have any window. I am not sure how to use processlist here too as i will have a list of lets say 5 instances but wont know for which instance i need to wait to finish before i continue the execution of the current instance. Or am i missing something here? Link to comment Share on other sites More sharing options...
guinness Posted October 21, 2013 Share Posted October 21, 2013 It's a function in my script guinness - what else?My bad. I thought the link was to MSDN by just the title and didn't check. Sorry. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
czardas Posted October 21, 2013 Share Posted October 21, 2013 (edited) I checked it - i cant use Win functions as my program doestn have any window. I am not sure how to use processlist here too as i will have a list of lets say 5 instances but wont know for which instance i need to wait to finish before i continue the execution of the current instance. Or am i missing something here? Run some tests. Instances should be in the order you run the programs (so I believe). Try it and check the process list with _ArrayDisplay(). See if you can interact with each instance of your executables. I thought the link was to MSDN by just the title and didn't check. Sorry. I only mentioned it because it's a simple demonstration, which I hoped might give Juvigy some ideas to play around with. Edited October 21, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Juvigy Posted October 21, 2013 Author Share Posted October 21, 2013 it doesnt look pretty but this is so far $list = ProcessList("111.exe") If $list[0][0] > 0 Then $stoperPID = $list[2][UBound($list,2)-1] ConsoleWrite($stoperPID&@CRLF) While _ArraySearch($list,$stoperPID, 0, 0, 0, 0, 1, 1) <> -1 If $list[0][0] < 2 Then ExitLoop Sleep(3000) $list = ProcessList("111.exe") WEnd EndIf Link to comment Share on other sites More sharing options...
czardas Posted October 22, 2013 Share Posted October 22, 2013 It looks like you're on the right track to me. Code doesn't have to be pretty, it just has to make sense. You should add comments. I'm assuming this is working now. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Solution water Posted October 22, 2013 Solution Share Posted October 22, 2013 (edited) I use a modified version of _Singleton to make sure that only one instance is running at a time:expandcollapse popupWhile 1 If _Singleton("xyz", 1) = 0 Then $iSleep = @AutoItPID * 10 Sleep($iSleep) Else ExitLoop EndIf WEnd ; #FUNCTION# ==================================================================================================================== ; Name...........: _Singleton ; Description ...: Enforce a design paradigm where only one instance of the script may be running. ; Syntax.........: _Singleton($sOccurenceName[, $iFlag = 0]) ; Parameters ....: $sOccurenceName - String to identify the occurrence of the script. This string may not contain the \ character unless you are placing the object in a namespace (See Remarks). ; $iFlag - Behavior options. ; |0 - Exit the script with the exit code -1 if another instance already exists. ; |1 - Return from the function without exiting the script. ; |2 - Allow the object to be accessed by anybody in the system. This is useful if specifying a "Global\" object in a multi-user environment. ; Return values .: Success - The handle to the object used for synchronization (a mutex). ; Failure - 0 ; Author ........: Valik ; Modified.......: ; Remarks .......: You can place the object in a namespace by prefixing your object name with either "Global\" or "Local\". "Global\" objects combined with the flag 2 are useful in multi-user environments. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _Singleton($sOccurenceName, $iFlag = 0) Local Const $ERROR_ALREADY_EXISTS = 183 Local $tSecurityAttributes = 0 Local $handle = DllCall("kernel32.dll", "handle", "CreateMutexW", "struct*", $tSecurityAttributes, "bool", 1, "wstr", $sOccurenceName) If @error Then Return SetError(@error, @extended, 0) Local $lastError = DllCall("kernel32.dll", "dword", "GetLastError") If @error Then Return SetError(@error, @extended, 0) If $lastError[0] = $ERROR_ALREADY_EXISTS Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $handle[0]) If @error Then Return SetError(@error, @extended, 0) If BitAND($iFlag, 1) Then Return SetError($lastError[0], $lastError[0], 0) Else Exit -1 EndIf EndIf Return $handle[0] EndFunc ;==>_Singleton Edited October 22, 2013 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
czardas Posted October 22, 2013 Share Posted October 22, 2013 (edited) I believe the OP wants processes to remain dormant until they become first in the queue, after earlier instances have terminated. It seems a good idea to use @AutoItPID, although I'm not 100% sure about this. PIDs may not always appear in sequence. I really don't know, not without running tests. Edited October 22, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted October 22, 2013 Share Posted October 22, 2013 That's exactly what my code does. I use it in an evironment where 30 instances of a script might be started by an application at the same time. czardas 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
czardas Posted October 22, 2013 Share Posted October 22, 2013 (edited) Ah okay water. I didn't notice the modified code lower down - duh. Nice example! Edited October 22, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted October 22, 2013 Share Posted October 22, 2013 >Here is the thread with the discussion why a modified version of _Singleton is needed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Juvigy Posted October 22, 2013 Author Share Posted October 22, 2013 Great. Thanks Water. Please have a look at my other thread about Outlook error and the issue with rules and attachments 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