Jump to content

Recommended Posts

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
Posted

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")
Posted

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!

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...