Jump to content

How to get process info ( like cpu and mem usage )


Recommended Posts

Hi all, i think my tittle was clear

as for now, with autoit and the integrated function i can get the name and the PID of the process, but i need the cpu usage and the memory usage, does you have any solution ?

thanks a lots !

Edited by pinkfoyd
Link to comment
Share on other sites

Hi,

you need to show it, or to save it? Cause when you want to save the data I wonder what that turns out, because it changes every lets say second.

Nevertheless, does the tasklist.exe of windows help?

Or do you need it to be done via Autoit?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

you need to show it, or to save it? Cause when you want to save the data I wonder what that turns out, because it changes every lets say second.

Nevertheless, does the tasklist.exe of windows help?

Or do you need it to be done via Autoit?

So long,

Mega

thank for helpin th.meger

PS : all what

in fact, it's for use with LCD Smartie ( soft for control an LCD screen )

I would writte on the screen certain process, like my web, FTP, and mail server for check all work well

exemple Posted Image

i would get the information each 15 minute for checking the process don't got to 100% ( hanging ) and ram up to high ( hanging too )

hope you will understand me

PS : "Nevertheless, does the tasklist.exe of windows help?" YES ! you right, i forgot this command, shame on me, now i have the memory use, but not the cpu usage of each process :whistle:

Edited by pinkfoyd
Link to comment
Share on other sites

HI,

you could also have a look at MemGetStats()

and

While 1
    Sleep(10)
    $cpu_usage = _Get_CPU_Usage(@ComputerName, 1, "taskmgr"); return usages if above the percent passed in
    If Not @error Then
        MsgBox(0, "CPU Usage", $cpu_usage)
        ExitLoop
    EndIf
WEnd

Func _Get_CPU_Usage($strComputer, $percent = 2, $strProcess = "")
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    
    If $strProcess <> "" Then $strProcess = " WHERE Name = '" & $strProcess & "'"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process" & $strProcess, "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) Then
        For $objItem In $colItems
            If Number($objItem.PercentProcessorTime) > Number($percent) Then Return $objItem.PercentProcessorTime
        Next
    EndIf
    SetError(1)
    Return ""
EndFunc  ;==>_Get_CPU_Usage

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

D:\Downloads\test.au3 (17) : ==> The requested action with this object has failed.:

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process" & $strProcess, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)^ ERROR

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 1.715

so bad :whistle: ( latest beta )

EDIT : i have a french version of windows, it's the problem ?

Edited by pinkfoyd
Link to comment
Share on other sites

Hi,

I don't think so. Works for me. I have XP Sp1. :">

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

thanks a lot th.meger

but i found another way :)

i just find this : http://www.teamcti.com/pview/prcview.htm

and with the command line : pv explo* -o"%c - %m"

it return the cpu usage (%c) and memory usage (%m) of the processus explorer.exe :whistle:

available info :

Format string can use the following placeholders to control the output

%a affinity, %d creation time, %c[time] % cpu

%f full path, %e elapsed cpu time, %i process id

%l command line, %n image name, %m memory (K)

%p priority, %r parent id, %s signature

%t thread count, %u user name, %v version

Specify an optional performance data collecting time in milliseconds after the %c switch, default is 500ms.

Edited by pinkfoyd
Link to comment
Share on other sites

  • 6 months later...

HI,

you could also have a look at MemGetStats()

and

While 1
    Sleep(10)
    $cpu_usage = _Get_CPU_Usage(@ComputerName, 1, "taskmgr"); return usages if above the percent passed in
    If Not @error Then
        MsgBox(0, "CPU Usage", $cpu_usage)
        ExitLoop
    EndIf
WEnd

Func _Get_CPU_Usage($strComputer, $percent = 2, $strProcess = "")
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    
    If $strProcess <> "" Then $strProcess = " WHERE Name = '" & $strProcess & "'"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process" & $strProcess, "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) Then
        For $objItem In $colItems
            If Number($objItem.PercentProcessorTime) > Number($percent) Then Return $objItem.PercentProcessorTime
        Next
    EndIf
    SetError(1)
    Return ""
EndFunc  ;==>_Get_CPU_Usage

So long,

Mega

Hi @th.meger

I tried out the script above (curosity) It seemed to be very slow. My PC is 1.5Ghz, 256MbRAM, WinXP Pro.

Attached is a graphic from my TaskManager Preformance tab while the script was running. The msgbox value was 50.

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Hi,

sorry there is nothing I can think of to speed it up. :">

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
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
 Share

  • Recently Browsing   0 members

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