jacky998877 Posted September 4, 2022 Share Posted September 4, 2022 how to sort this list, i only need the process id and it should > 4 $list = ProcessList() Link to comment Share on other sites More sharing options...
taurus905 Posted September 4, 2022 Share Posted September 4, 2022 (edited) Try this: ; Sort ProcessList #include <Array.au3> Global $sa2_ProcessList = ProcessList() _ArrayDisplay($sa2_ProcessList, "$sa2_ProcessList") _ArraySort($sa2_ProcessList, 0 , 1, 0, 1) ; Sort by 2nd column _ArrayDisplay($sa2_ProcessList, "$sa2_ProcessList") Edited September 4, 2022 by taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
jacky998877 Posted September 4, 2022 Author Share Posted September 4, 2022 10 minutes ago, taurus905 said: Try this: ; Sort ProcessList #include <Array.au3> Global $sa2_ProcessList = ProcessList() _ArrayDisplay($sa2_ProcessList, "$sa2_ProcessList") _ArraySort($sa2_ProcessList, 0 , 1, 0, 1) ; Sort by 2nd column _ArrayDisplay($sa2_ProcessList, "$sa2_ProcessList") my bad , i didnt explain it clearly, i want only the item in the second column, and the PIDs should > 4 Link to comment Share on other sites More sharing options...
taurus905 Posted September 4, 2022 Share Posted September 4, 2022 (edited) This isn't the shortest or best way, but it should allow you to follow and edit to suit your needs. ; Sort ProcessList #include <Array.au3> Global $sa2_ProcessList = ProcessList() _ArrayDisplay($sa2_ProcessList, "Original") _ArraySort($sa2_ProcessList, 0 , 1, 0, 1) ; Sort by 2nd column _ArrayDisplay($sa2_ProcessList, "Sorted") For $i = 1 To UBound($sa2_ProcessList) - 1 If $sa2_ProcessList[$i][1] <= 5 Then _ArrayDelete($sa2_ProcessList, $i) $sa2_ProcessList[0][0] -= 1 $i -= 1 Else ExitLoop EndIf Next _ArrayDisplay($sa2_ProcessList, "PIDs > 4") $sa2_ProcessList[0][1] = $sa2_ProcessList[0][0] & " PIDs > 4" _ArrayColDelete($sa2_ProcessList, 0) _ArrayDisplay($sa2_ProcessList, "Just PIDs > 4") Edited September 5, 2022 by taurus905 Subz 1 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
jacky998877 Posted September 4, 2022 Author Share Posted September 4, 2022 (edited) 6 minutes ago, taurus905 said: This isn't the shortest or best way, but it should allow you to follow and edit to suit your needs. ; Sort ProcessList #include <Array.au3> Global $sa2_ProcessList = ProcessList() _ArrayDisplay($sa2_ProcessList, "Original") _ArraySort($sa2_ProcessList, 0 , 1, 0, 1) ; Sort by 2nd column _ArrayDisplay($sa2_ProcessList, "Sorted") For $i = 1 To UBound($sa2_ProcessList) - 1 If $sa2_ProcessList[$i][1] <= 5 Then _ArrayDelete($sa2_ProcessList, $i) $sa2_ProcessList[0][0] -= 1 $i -= 1 Else ExitLoop EndIf Next _ArrayDisplay($sa2_ProcessList, "PIDs > 4") $sa2_ProcessList[0][1] = $sa2_ProcessList[0][0] & "PIDs > 4" _ArrayColDelete($sa2_ProcessList, 0) _ArrayDisplay($sa2_ProcessList, "Just PIDs > 4") this script works , thanks for the effort man 😂 Edited September 4, 2022 by jacky998877 taurus905 1 Link to comment Share on other sites More sharing options...
Subz Posted September 4, 2022 Share Posted September 4, 2022 Another way based on @taurus905 code: #include <Array.au3> Global $aProcesses = ProcessList() _ArrayDelete($aProcesses, 0) ;~ Delete first row _ArrayColDelete($aProcesses, 0) ;~ Delete first column _ArraySort($aProcesses) ;~ Sort Array _ArrayDisplay($aProcesses, ":: Before ::") For $i = UBound($aProcesses) - 1 To 0 Step - 1 If $aProcesses[$i][0] <=5 Then _ArrayDelete($aProcesses, $i) Next _ArrayDisplay($aProcesses, ":: After ::") taurus905 and jacky998877 1 1 Link to comment Share on other sites More sharing options...
jacky998877 Posted September 5, 2022 Author Share Posted September 5, 2022 30 minutes ago, Subz said: Another way based on @taurus905 code: #include <Array.au3> Global $aProcesses = ProcessList() _ArrayDelete($aProcesses, 0) ;~ Delete first row _ArrayColDelete($aProcesses, 0) ;~ Delete first column _ArraySort($aProcesses) ;~ Sort Array _ArrayDisplay($aProcesses, ":: Before ::") For $i = UBound($aProcesses) - 1 To 0 Step - 1 If $aProcesses[$i][0] <=5 Then _ArrayDelete($aProcesses, $i) Next _ArrayDisplay($aProcesses, ":: After ::") first thanks for the solution you provided, i was trying to make further progress based on you code ,so that i can close the items in the list , this is the code for $a in $aProcesses ProcessClose($a) Next my code didnt work , neither any errors are being displayed in the console , do you have any idea? Link to comment Share on other sites More sharing options...
Subz Posted September 5, 2022 Share Posted September 5, 2022 You would need to use the following to loop through the list, although note that a number of processes cannot be closed using this method, what is the objective? For $a = 0 To Ubound($aProcesses) - 1 Link to comment Share on other sites More sharing options...
jacky998877 Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 5 minutes ago, Subz said: You would need to use the following to loop through the list, although note that a number of processes cannot be closed using this method, what is the objective? For $a = 0 To Ubound($aProcesses) - 1 i tried it also , no luck , i wnat to build a litte program to shut down the computer, for the default shut down fucntion of windows7, each time it will ask again to close the opened programs Edited September 5, 2022 by jacky998877 Link to comment Share on other sites More sharing options...
Subz Posted September 5, 2022 Share Posted September 5, 2022 Sorry forgot the rest of the code: For $a = 0 To Ubound($aProcesses) - 1 ProcessClose($aProcesses[$a]) Next Shutdown function should also ask the user to close programs, it only forces the shutdown if you use Shutdown(BitOr($SD_SHUTDOWN,$SD_FORCE)) Link to comment Share on other sites More sharing options...
jacky998877 Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 6 minutes ago, Subz said: Sorry forgot the rest of the code: For $a = 0 To Ubound($aProcesses) - 1 ProcessClose($aProcesses[$a]) Next Shutdown function should also ask the user to close programs, it only forces the shutdown if you use Shutdown(BitOr($SD_SHUTDOWN,$SD_FORCE)) it is ok, i already tried it before you update, still , an error ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: ProcessClose($aProcesses[$a]) ProcessClose(^ ERROR Edited September 5, 2022 by jacky998877 Link to comment Share on other sites More sharing options...
Subz Posted September 5, 2022 Share Posted September 5, 2022 Sorry, forgot when you convert a 2D array to 1D array you still need to reference the column, so try: For $a = 0 To Ubound($aProcesses) - 1 ProcessClose($aProcesses[$a][0]) Next jacky998877 1 Link to comment Share on other sites More sharing options...
jacky998877 Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 15 minutes ago, Subz said: Sorry, forgot when you convert a 2D array to 1D array you still need to reference the column, so try: For $a = 0 To Ubound($aProcesses) - 1 ProcessClose($aProcesses[$a][0]) Next yep , it worked out pefectly according to its own will, the moment it is being executed, my computer give me a blue screen , accutually i already took care of the problem , at least i think so, by deleting the process PID which is lesser then 4 , this is a dangerous program Edited September 5, 2022 by jacky998877 Link to comment Share on other sites More sharing options...
mikell Posted September 5, 2022 Share Posted September 5, 2022 10 hours ago, Subz said: Another way... My 2 cents - for the fun #include <Array.au3> $a = ProcessList() _ArrayDisplay($a) $r = StringSplit(_ArrayToString($a, "|", 3, $a[0][0], @crlf, 1, 1), @crlf, 3) _ArrayDisplay($r) Just check before running if 3 is the right index to start on jacky998877 1 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