RogFleming Posted July 28, 2009 Share Posted July 28, 2009 I use a foreach statements in TCL code, but have not figured out how to perform that process in Autoit. What I want to do is have a program which when a process starts, that the program will be able to act on it. but I want to use a list of programs to watch for. expandcollapse popupTCL Code proc AppProcessCheck {} { SetErrorMode resume SetTimeout 50msec global _SSOERR CloseWindows "*Internet Explorer*" CloseWindows "*THR Mainframe*" DisplayStatusBox "Checking for Open Applications" set user_apps { IEXPLORE.EXE notepad.exe wordpad.exe winword.exe excel.exe powerpnt.exe acrord32.exe Outlook.exe wmplayer.exe MSACCESS.EXE SeAM.exe ess.exe PFM.exe FMReports.exe CPhostpro.exe wfront.exe javaws.exe javaw.exe AtStaff.exe costart.exe VNEXPLORE.exe IEExec.exe DocNeTExplorer.exe RoutingQueueView.exe TRANSFER.exe CVIEWER.exe VNEXPLORE.exe LISTDB.exe Medstat.exe carestat.exe CU.exe ExitCare.exe Elig.exe cvis0054.exe SQStart.exe ogu00.EXE VIPRDE.exe scguiw32.exe fbkLoad.exe Launch.exe WDDspPag.Bin XTND.EXE} set process_list_exe_name "tasklist.exe" ;# from Windows install set winuser "[GetWindowsUserName]" set std_out "" catch {set std_out [exec $process_list_exe_name /NH /FI "USERNAME eq texas\\$winuser"]} set data [split $std_out "\n"] foreach line $data { set endstrg [string first " " $line] set runapp [string range $line 0 [expr {$endstrg - 1}]] if {$runapp != ""} { foreach chkapp $user_apps { if {[string match -nocase "$runapp*" $chkapp]} { TerminateProcesses $runapp } } } } return } any help would be great, basically I looking to compare a static array and dynamic array and if I find a match then perform a task. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2009 Moderators Share Posted July 28, 2009 RogFleming,Try looping _ArraySearch like this:#include <Array.au3> ; This would be the list of processes you wished to act on Global $aArray_Static[3] = ["Tom", "Dick", "Harry"] ; This would be the actual process list Global $aArray_Dynamic[5] = ["Fred", "Dick", "Tom", "Bert", "Harry"] For $i = 0 To UBound($aArray_Static) - 1 If _ArraySearch($aArray_Dynamic, $aArray_Static[$i]) <> -1 Then MsgBox(0, "Found!", $aArray_Static[$i]) ; Do something with $aArray_Static[$i] EndIf NextM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RogFleming Posted August 4, 2009 Author Share Posted August 4, 2009 Wow, Thanks, that was easy (pushes the button) Thanks, Roger Link to comment Share on other sites More sharing options...
ankushsingh Posted July 9, 2012 Share Posted July 9, 2012 (edited) IT WORKS FINE FOR ME --------------------------------------------------------- Func _ArrayCompare($ar1, $ar2) $ArrayCount_1=_ArraySize($ar1) $ArrayCount_2=_ArraySize($ar2) dim $CommonItemsArray[1] $Array_i1=0 while($Array_i1< $ArrayCount_1) $Array_i2=0 While($Array_i2 < $ArrayCount_2) if (StringInStr ($ar1[$Array_i1],$ar2[$Array_i2])) then _ArrayAdd($CommonItemsArray,$ar2[$Array_i2]) ExitLoop EndIf $Array_i2=$Array_i2+1 WEnd $Array_i1= $Array_i1+1 WEnd _ArrayDelete($CommonItemsArray,0) return $CommonItemsArray Endfunc Edited July 9, 2012 by ankushsingh 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