Sign in to follow this  
Followers 0
nf67

ProcessGetStats() doesn't return an array?

5 posts in this topic

#1 ·  Posted (edited)

Hi there,

this is a quick script I've created to demonstrate the problem, is there anyone that could get this to work?

#include <Process.au3>
$Processes = ProcessList()
For $Process = 1 to $Processes[0][0]
    $Memory = ProcessGetStats($Processes[$Process][1]) ;Fails, returns 0. Therefore, it isn't an array and the script crashes later on.
    FileWriteLine(@ScriptDir & "Processes.txt","--Name:" & $Processes[$Process][0] & _
    " --Priority:"& _ProcessGetPriority($Processes[$Process][1]) & _
    " --Work Memory:"& $Memory[0] & _
    " --Peak Memory:"& $Memory[1])
Next
ShellExecute(@ScriptDir & "Processes.txt")

Thanks a bunch,

;)

Edited by nf67

Share this post


Link to post
Share on other sites



You forgot the slash after @scriptdir

ShellExecute(@ScriptDir & "\Processes.txt")

And to stop the crash check the return value:

Return Value

Success: An array of infos data (See Remarks).

Failure: 0.

Example:

#include <Process.au3>
$Processes = ProcessList()
For $Process = 1 to $Processes[0][0]
    $Memory = ProcessGetStats($Processes[$Process][1]) ;Fails, returns 0. Therefore, it isn't an array and the script crashes later on.
    If $Memory = 0 Then ContinueLoop
    FileWriteLine(@ScriptDir & "\Processes.txt","--Name:" & $Processes[$Process][0] & _
    " --Priority:"& _ProcessGetPriority($Processes[$Process][1]) & _
    " --Work Memory:"& $Memory[0] & _
    " --Peak Memory:"& $Memory[1])
Next
ShellExecute(@ScriptDir & "\Processes.txt")

Or:

#include <Process.au3>
$Processes = ProcessList()
For $Process = 1 to $Processes[0][0]
    $Memory = ProcessGetStats($Processes[$Process][1]) ;Fails, returns 0. Therefore, it isn't an array and the script crashes later on.
    FileWriteLine(@ScriptDir & "\Processes.txt","--Name:" & $Processes[$Process][0] & _
    " --Priority:"& _ProcessGetPriority($Processes[$Process][1]))
    If $Memory <> 0 Then
        FileWriteLine(@ScriptDir & "\Processes.txt", " --Work Memory:"& $Memory[0] & _
        " --Peak Memory:"& $Memory[1])
    EndIf
Next
ShellExecute(@ScriptDir & "\Processes.txt")

Share this post


Link to post
Share on other sites

Yes I had already implemented such a check, but that's not really my main problem, sorry.

If the list of processes is retrieved by ProcessList() just a milisecond before ProcessGetStats() runs, why would it ever fail?

Sorry for the slashes!

Share this post


Link to post
Share on other sites

I don't know, but by looking at Processes.txt from the second script in my post I would say it's services and stuff that you aren't supposed to touch. Also doing ProcessGetStats on an app with higher privileges seems to fail.

Run as admin to get as much information as possible=

#RequireAdmin ;for au3-files

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator ;for exe-files

Share this post


Link to post
Share on other sites

Thanks for your info, Alkex, I'll include that. ;)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0