Jump to content



Photo

This must be a better way to do this (array compare)


  • Please log in to reply
5 replies to this topic

#1 awurthmann

awurthmann

    Seeker

  • New Members
  • 3 posts

Posted 18 May 2012 - 04:58 PM

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.





#2 water

water

    ?

  • MVPs
  • 10,677 posts

Posted 18 May 2012 - 05:03 PM

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.

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.

You don't need to do it yourself. When compiling the script select Obfuscator and use option /striponly to remove unused functions and variables.

UDFs:

Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts

WordEX (2012-12-29 - Version 1.3 released) - Download

ExcelEX (2013-05-11 - Alpha 4 released) - Download


#3 awurthmann

awurthmann

    Seeker

  • New Members
  • 3 posts

Posted 18 May 2012 - 05:07 PM

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....

#4 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 18 May 2012 - 05:13 PM

#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


#5 kylomas

kylomas

    Want to see God laugh? Tell him you have plans!

  • Active Members
  • PipPipPipPipPipPip
  • 2,043 posts

Posted 18 May 2012 - 05:13 PM

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
"Really?, How Do you know the're not random numbers?"Forum Rules

#6 awurthmann

awurthmann

    Seeker

  • New Members
  • 3 posts

Posted 18 May 2012 - 05:48 PM

#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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users