awurthmann Posted May 18, 2012 Posted May 18, 2012 I'm struggling with the following which is a sort of a "if these processes are running kill them". Note the code below does work however it is a tad messy and not as dynamic as I would like. The goal here is this. Find processes that are LIKE those in the $clist array and close them (aka kill them). For example if notepad.exe is running kill it, if notepad++.exe is running kill it; cal.exe, calc.exe; cmd.exe, etc... Local $clist[3] = ["notep", "cal", "cmd"] Local $plist = ProcessList() For $i = 1 To $plist[0][0] $psname=$plist[$i][0] $result = StringInStr($psname, $clist[2]) if $result <> 0 Then ProcessClose($psname) $result = StringInStr($psname, $clist[1]) if $result <> 0 Then ProcessClose($psname) $result = StringInStr($psname, $clist[0]) if $result <> 0 Then ProcessClose($psname) Next PS If you really think I should use the array include please, if you can, recite which functions. I need the code to be as small as possible so I'll need to pull out those specific array functions.
water Posted May 18, 2012 Posted May 18, 2012 Maybe Regular Expressions might shorten your code a bit. I'm no expert so can't give you any advice but maybe someone knowledgeable jumps in.PSIf you really think I should use the array include please, if you can, recite which functions. I need the code to be as small as possible so I'll need to pull out those specific array functions.You don't need to do it yourself. When compiling the script select Obfuscator and use option /striponly to remove unused functions and variables. 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
awurthmann Posted May 18, 2012 Author Posted May 18, 2012 When compiling the script select Obfuscator and use option /striponly to remove unused functions and variables.I did not know that, thank you. Now if only I could figure out a cleaner way to do this compare. Hrmmmm....
Zedna Posted May 18, 2012 Posted May 18, 2012 #AutoIt3Wrapper_run_obfuscator=y #Obfuscator_parameters=/striponly Local $clist = StringSplit('notep,cal,cmd',',') Local $plist = ProcessList() For $i = 1 To $plist[0][0] $psname = $plist[$i][0] For $j = 1 To $clist[0] If StringInStr($psname, $clist[$j]) <> 0 Then ProcessClose($psname) Next Next Resources UDF ResourcesEx UDF AutoIt Forum Search
kylomas Posted May 18, 2012 Posted May 18, 2012 awurthman, try this Local $clist[3] = ["notep", "cal", "cmd"], $plist = ProcessList() For $i = 1 To $plist[0][0] for $j = 0 to ubound($clist) - 1 if stringinstr($plist[$i][0],$clist[$j]) > 0 then processclose($plist[$i][0]) next Next kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
awurthmann Posted May 18, 2012 Author Posted May 18, 2012 #AutoIt3Wrapper_run_obfuscator=y #Obfuscator_parameters=/striponly Local $clist = StringSplit('notep,cal,cmd',',') Local $plist = ProcessList() For $i = 1 To $plist[0][0] $psname = $plist[$i][0] For $j = 1 To $clist[0] If StringInStr($psname, $clist[$j]) <> 0 Then ProcessClose($psname) Next Next Thank you much sir!
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