TheSpannish Posted May 23, 2015 Share Posted May 23, 2015 Hi all, AutoIt its my first programming lenguaje, i had been codding like for 1 year but i have never use arrays, now i need to use them i just tryed to learn about that, but I dont think I learn nothing. If someone can help me to understand how they work... Also if you can help me with this array in my code I will really thank!expandcollapse popup#RequireAdmin #notrayicon #include <ProcessInfo.au3> #include <Array.au3> #include <Toast.au3> if Not ProcessExists("svchost.exe") Then MsgBox(16,"Error","The process havent been founded :(") Exit EndIf _Toast_Set(0) _Toast_Show(@ScriptFullPath,"Svchost Checker","Checking the svchost..."&@CRLF&"This will take some time, please wait",0,True,True) Local $arraym[15][3] = [[1, 2, 3], [2, 3, 4], [3, 4, 5],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]]] MsgBox(0,"","array created") $proceso=_ProcessListProperties("svchost.exe") For $x=1 To $proceso[0][0] $isput=0 $command=StringSplit($proceso[$x][9]," ") If $command[1]<>@SystemDir&"\svchost.exe" Then $arraym[$x][1]="The file its not at the usually directory" $arraym[$x][2]=$command[1] $isput=1 $arraym[0][0]=$arraym[0][0]+1 EndIf If $command[2]<>"-k" Then If $arraym[$x][1]<>"" then $arraym[$x][1]="Not acting like a normal svchost behaviour" $arraym[$x][2]=$command[1] EndIf If $isput<>0 Then $arraym[0][0]=$arraym[0][0]+1 EndIf EndIf Next _Toast_Hide() _Toast_Set(0) If $arraym[0][0]>0 Then _Toast_Show(@ScriptFullPath,"Svchost Checker","We found"&$arraym[0][0],0,True,True) Else _Toast_Show(@ScriptFullPath,"Svchost Checker","It seems that the process svchost its correct :)",0,True,True) Sleep(8000) _Toast_Hide() Exit EndIf For $g=1 To $arraym[0][0] MsgBox(4144,"Svchost checker","Problem "&$g&" of "&$arraym[0][0]&@CRLF&"Path: "&$arraym[$g][2]&@CRLF&"Reason: "&$arraym[$g][1]) Next Codding its just my life! :thumbsup: Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 23, 2015 Moderators Share Posted May 23, 2015 (edited) TheSpannish, i have never use arraysI suggest reading the Arrays tutorial in the Wiki - that will give you a good grounding. I will look at your script later this evening.M23Edit: Where do you find ProcessInfo.au3? Edited May 23, 2015 by Melba23 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...
argumentum Posted May 24, 2015 Share Posted May 24, 2015 ..since is within the topic. In the page in the wiki, there is an example that shows:Local Const $myArray[5] = [1, 2, 3, 4, 5] displayArray($myArray) Func displayArray(Const $array) ; <-- should that not be ByRef ?? Local Const $arrayLength = UBound($array) For $i = 0 To $arrayLength - 1 MsgBox($MB_OK, "displayArray", $array[$i]) Next EndFuncshould that not be ByRef ?? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
TheSpannish Posted May 24, 2015 Author Share Posted May 24, 2015 Where do you find ProcessInfo.au3?expandcollapse popup;=============================================================================== ; Function Name: _ProcessListProperties() ; Description: Get various properties of a process, or all processes ; Call With: _ProcessListProperties( [$Process [, $sComputer]] ) ; Parameter(s): (optional) $Process - PID or name of a process, default is "" (all) ; (optional) $sComputer - remote computer to get list from, default is local ; Requirement(s): AutoIt v3.2.4.9+ ; Return Value(s): On Success - Returns a 2D array of processes, as in ProcessList() ; with additional columns added: ; [0][0] - Number of processes listed (can be 0 if no matches found) ; [1][0] - 1st process name ; [1][1] - 1st process PID ; [1][2] - 1st process Parent PID ; [1][3] - 1st process owner ; [1][4] - 1st process priority (0 = low, 31 = high) ; [1][5] - 1st process executable path ; [1][6] - 1st process CPU usage ; [1][7] - 1st process memory usage ; [1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23) ; [1][9] - 1st process command line string ; ... ; [n][0] thru [n][9] - last process properties ; On Failure: Returns array with [0][0] = 0 and sets @Error to non-zero (see code below) ; Author(s): PsaltyDS at http://www.autoitscript.com/forum ; Date/Version: 12/01/2009 -- v2.0.4 ; Notes: If an integer PID or string process name is provided and no match is found, ; then [0][0] = 0 and @error = 0 (not treated as an error, same as ProcessList) ; This function requires admin permissions to the target computer. ; All properties come from the Win32_Process class in WMI. ; To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used. ;=============================================================================== Func _ProcessListProperties($Process = "", $sComputer = ".") Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate Local $avProcs[1][2] = [[0, ""]], $n = 1 ; Convert PID if passed as string If StringIsInt($Process) Then $Process = Int($Process) ; Connect to WMI and get process objects $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $sComputer & "\root\cimv2") If IsObj($oWMI) Then ; Get collection processes from Win32_Process If $Process == "" Then ; Get all $colProcs = $oWMI.ExecQuery("select * from win32_process") ElseIf IsInt($Process) Then ; Get by PID $colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process) Else ; Get by Name $colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'") EndIf If IsObj($colProcs) Then ; Return for no matches If $colProcs.count = 0 Then Return $avProcs ; Size the array ReDim $avProcs[$colProcs.count + 1][10] $avProcs[0][0] = UBound($avProcs) - 1 ; For each process... For $oProc In $colProcs ; [n][0] = Process name $avProcs[$n][0] = $oProc.name ; [n][1] = Process PID $avProcs[$n][1] = $oProc.ProcessId ; [n][2] = Parent PID $avProcs[$n][2] = $oProc.ParentProcessId ; [n][3] = Owner If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName ; [n][4] = Priority $avProcs[$n][4] = $oProc.Priority ; [n][5] = Executable path $avProcs[$n][5] = $oProc.ExecutablePath ; [n][8] = Creation date/time $dtmDate = $oProc.CreationDate If $dtmDate <> "" Then ; Back referencing RegExp pattern from weaponx Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)" $dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6") EndIf $avProcs[$n][8] = $dtmDate ; [n][9] = Command line string $avProcs[$n][9] = $oProc.CommandLine ; increment index $n += 1 Next Else SetError(2); Error getting process collection from WMI EndIf ; release the collection object $colProcs = 0 ; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process ; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher") $colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet $oRefresher.Refresh ; Time delay before calling refresher Local $iTime = TimerInit() Do Sleep(20) Until TimerDiff($iTime) >= 100 $oRefresher.Refresh ; Get PerfProc data For $oProc In $colProcs ; Find it in the array For $n = 1 To $avProcs[0][0] If $avProcs[$n][1] = $oProc.IDProcess Then ; [n][6] = CPU usage $avProcs[$n][6] = $oProc.PercentProcessorTime ; [n][7] = memory usage $avProcs[$n][7] = $oProc.WorkingSet ExitLoop EndIf Next Next Else SetError(1); Error connecting to WMI EndIf ; Return array Return $avProcs EndFunc ;==>_ProcessListPropertiesWhat i mean is, are the arrays good in the program? I have readed the wiki and didnt understand Codding its just my life! :thumbsup: Link to comment Share on other sites More sharing options...
argumentum Posted May 24, 2015 Share Posted May 24, 2015 look at it as a spreadsheet table, because a 2 dimensional array is pretty much that to visualize. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted May 24, 2015 Share Posted May 24, 2015 I looked at your code and made a mess .... but functional. Try it out: expandcollapse popup#RequireAdmin #notrayicon ;~ #include <ProcessInfo.au3> #include <Array.au3> ;~ #include <Toast.au3> if Not ProcessExists("svchost.exe") Then MsgBox(16,"Error","The process havent been founded :(") Exit EndIf ;~ _Toast_Set(0) Func _Toast_Show($1="",$2="",$3="",$4="",$5="",$6="") ; my fake "_Toast_Show" ToolTip( $1 , 20,20,$2 ) ConsoleWrite( $1&@CRLF&@TAB&$2&@CRLF&@CRLF) EndFunc _Toast_Show(@ScriptFullPath,"Svchost Checker","Checking the svchost..."&@CRLF&"This will take some time, please wait",0,True,True) Local $arraym[15][3] = [[1, 2, 3], [2, 3, 4], [3, 4, 5],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]] MsgBox(0,"","array created") $proceso=_ProcessListProperties("svchost.exe") For $x=1 To $proceso[0][0] $isput=0 $command=StringSplit($proceso[$x][9]," ") If $command[1]<>@SystemDir&"\svchost.exe" Then $arraym[$x][1]="The file its not at the usually directory" $arraym[$x][2]=$command[1] $isput=1 $arraym[0][0]=$arraym[0][0]+1 EndIf If $command[2]<>"-k" Then If $arraym[$x][1]<>"" then $arraym[$x][1]="Not acting like a normal svchost behaviour" $arraym[$x][2]=$command[1] EndIf If $isput<>0 Then $arraym[0][0]=$arraym[0][0]+1 EndIf EndIf Next ;~ _Toast_Hide() ;~ _Toast_Set(0) If $arraym[0][0]>0 Then _Toast_Show(@ScriptFullPath,"Svchost Checker","We found"&$arraym[0][0],0,True,True) Else _Toast_Show(@ScriptFullPath,"Svchost Checker","It seems that the process svchost its correct :)",0,True,True) Sleep(8000) ;~ _Toast_Hide() Exit EndIf For $g=1 To $arraym[0][0] MsgBox(4144,"Svchost checker","Problem "&$g&" of "&$arraym[0][0]&@CRLF&"Path: "&$arraym[$g][2]&@CRLF&"Reason: "&$arraym[$g][1]) Next ;=============================================================================== ; Function Name: _ProcessListProperties() ; Description: Get various properties of a process, or all processes ; Call With: _ProcessListProperties( [$Process [, $sComputer]] ) ; Parameter(s): (optional) $Process - PID or name of a process, default is "" (all) ; (optional) $sComputer - remote computer to get list from, default is local ; Requirement(s): AutoIt v3.2.4.9+ ; Return Value(s): On Success - Returns a 2D array of processes, as in ProcessList() ; with additional columns added: ; [0][0] - Number of processes listed (can be 0 if no matches found) ; [1][0] - 1st process name ; [1][1] - 1st process PID ; [1][2] - 1st process Parent PID ; [1][3] - 1st process owner ; [1][4] - 1st process priority (0 = low, 31 = high) ; [1][5] - 1st process executable path ; [1][6] - 1st process CPU usage ; [1][7] - 1st process memory usage ; [1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23) ; [1][9] - 1st process command line string ; ... ; [n][0] thru [n][9] - last process properties ; On Failure: Returns array with [0][0] = 0 and sets @Error to non-zero (see code below) ; Author(s): PsaltyDS at http://www.autoitscript.com/forum ; Date/Version: 12/01/2009 -- v2.0.4 ; Notes: If an integer PID or string process name is provided and no match is found, ; then [0][0] = 0 and @error = 0 (not treated as an error, same as ProcessList) ; This function requires admin permissions to the target computer. ; All properties come from the Win32_Process class in WMI. ; To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used. ;=============================================================================== Func _ProcessListProperties($Process = "", $sComputer = ".") Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate Local $avProcs[1][2] = [[0, ""]], $n = 1 ; Convert PID if passed as string If StringIsInt($Process) Then $Process = Int($Process) ; Connect to WMI and get process objects $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $sComputer & "\root\cimv2") If IsObj($oWMI) Then ; Get collection processes from Win32_Process If $Process == "" Then ; Get all $colProcs = $oWMI.ExecQuery("select * from win32_process") ElseIf IsInt($Process) Then ; Get by PID $colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process) Else ; Get by Name $colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'") EndIf If IsObj($colProcs) Then ; Return for no matches If $colProcs.count = 0 Then Return $avProcs ; Size the array ReDim $avProcs[$colProcs.count + 1][10] $avProcs[0][0] = UBound($avProcs) - 1 ; For each process... For $oProc In $colProcs ; [n][0] = Process name $avProcs[$n][0] = $oProc.name ; [n][1] = Process PID $avProcs[$n][1] = $oProc.ProcessId ; [n][2] = Parent PID $avProcs[$n][2] = $oProc.ParentProcessId ; [n][3] = Owner If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName ; [n][4] = Priority $avProcs[$n][4] = $oProc.Priority ; [n][5] = Executable path $avProcs[$n][5] = $oProc.ExecutablePath ; [n][8] = Creation date/time $dtmDate = $oProc.CreationDate If $dtmDate <> "" Then ; Back referencing RegExp pattern from weaponx Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)" $dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6") EndIf $avProcs[$n][8] = $dtmDate ; [n][9] = Command line string $avProcs[$n][9] = $oProc.CommandLine ; increment index $n += 1 Next Else SetError(2); Error getting process collection from WMI EndIf ; release the collection object $colProcs = 0 ; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process ; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher") $colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet If Not IsObj($colProcs) Then Return $avProcs ; <---- it was failing here $oRefresher.Refresh ; Time delay before calling refresher Local $iTime = TimerInit() Do Sleep(20) Until TimerDiff($iTime) >= 100 $oRefresher.Refresh ; Get PerfProc data For $oProc In $colProcs ; Find it in the array For $n = 1 To $avProcs[0][0] If $avProcs[$n][1] = $oProc.IDProcess Then ; [n][6] = CPU usage $avProcs[$n][6] = $oProc.PercentProcessorTime ; [n][7] = memory usage $avProcs[$n][7] = $oProc.WorkingSet ExitLoop EndIf Next Next Else SetError(1); Error connecting to WMI EndIf ; Return array Return $avProcs EndFunc ;==>_ProcessListProperties TheSpannish 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted May 24, 2015 Share Posted May 24, 2015 TheSpannish, if the answers you found here, are the answers to your questions, then please mark the topic as answered. That way I can unplug my attention from the subject. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
TheSpannish Posted June 2, 2015 Author Share Posted June 2, 2015 how i do that? Codding its just my life! :thumbsup: Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 2, 2015 Moderators Share Posted June 2, 2015 TheSpannish,The new forum software no longer has that functionality - but if you wish you could amend the thread title by editing the first post. Or argumentum could stop following the thread by using the app at top right.M23 argumentum 1 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...
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