Sign in to follow this  
Followers 0
Ayke

IDLE Time from Process

8 posts in this topic

Hello,

is there a function which tells me how long a process is running ?

CPU-TIME and IDLE Time would be fine.

Actually i use pslist from sysinternals to get the information, i write it down into a file and then i again read it with autoit.

It Works but it could be better :|

Regards


www.m3rry.de | nach müde kommt blöd

Share this post


Link to post
Share on other sites



Have a look at this.

I'm at a shared computer so I cannot work out an example though...


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

You could try something like this as well. You'd just have to parse the datetime string.

$sComputer = "."

$oWmi = ObjGet("winmgmts:\\" & $sComputer & "\root\cimv2")
$oClass = $oWmi.ExecQuery("Select * from Win32_Process")

For $obj in $oClass
        msgbox(1,"",$obj.Name & " Created: " & $obj.CreationDate)
Next

Share this post


Link to post
Share on other sites

You could try something like this as well. You'd just have to parse the datetime string.

$sComputer = "."

$oWmi = ObjGet("winmgmts:\\" & $sComputer & "\root\cimv2")
$oClass = $oWmi.ExecQuery("Select * from Win32_Process")

For $obj in $oClass
        msgbox(1,"",$obj.Name & " Created: " & $obj.CreationDate)
NextoÝ÷ Ûú®¢×«¢é]mç±µéÝyÖòªç«Ëbè­«)yÈÊk¡Ç¬±«­¢+ØÀÌØí½]µ¤ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈì¸ÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(ÀÌØí½
±ÍÌôÀÌØí½]µ¤¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}AɽÍÌ]¡É9µôÌäíÕѽ¥Ð̹áÌäìÅÕ½Ðì¤()½ÈÀÌØí½¨¥¸ÀÌØí½
±ÍÌ(%µÍ½à Ä°ÅÕ½ÐìÅÕ½Ðì°ÀÌØí½¨¹9µµÀìÅÕ½Ðì
ÉÑèÅÕ½ÐìµÀìÀÌØí½¨¹
ÉÑ¥½¹Ñ¤)9áoÝ÷ ÚÚºÚ"µÍÌÍÛÕÛZHHØÙ]
    ][ÝÝÚ[YÛ]ÎÌLÉÌLËÌLÜÛÝ  ÌLØÚ[]][ÝÊBÌÍÛÐÛÜÈH ÌÍÛÕÛZK^XÔ]YJ ][ÝÔÙ[XÝ
ÛHÚ[ÌÔØÙÜÈÚHØÙÜÒYH ÌÎNÉ][ÝÈ   [È]]Ò]Q   [È ][ÝÉÌÎNÉ][ÝÊBÜ  ÌÍÛØ[   ÌÍÛÐÛÜÂ[ÙØÞ
K   ][ÝÉ][ÝË    ÌÍÛØ[YH [È ][ÝÈÜX]Y ][ÝÈ  [È ÌÍÛØÜX][Û]JB^

Adiditonal way of query the Win32_Process class can be found here: http://msdn2.microsoft.com/en-us/library/a...372(VS.85).aspx

Share this post


Link to post
Share on other sites

I don't had time right now to check any answer, im on it this Weekend, thanks for your reply.

Feedback soon :D


www.m3rry.de | nach müde kommt blöd

Share this post


Link to post
Share on other sites

I changed the Select to ProcessID and killed the PID not Processname

Its better, if you have multiple proccesses running and you want to make sure to pick the right one.

Added a CloseProcess after specific duration (was one of my targets).

#include <Date.au3>
$pname = "Notepad.exe" ; processname
$idletime = 24 ; time after $pname gets closed

Idle()

Func Idle()

    $pid = ProcessExists ($pname)
    $ptime = ProcessStartDateTime($pid)

    $datecalc = _DateDiff( 'h',$ptime,_NowCalc())
    ;MsgBox( 4096, $pname, "is running since : " & $datecalc &  " hours" )

If $datecalc > $idletime Then
    ProcessClose($pid)
EndIf
EndFunc

Func ProcessStartDateTime($psdtid)
   
    $objwmi = ObjGet("winmgmts:\\localhost\root\CIMV2")
   
    $psdtquery = "SELECT * FROM Win32_Process WHERE ProcessID = " & $psdtid
   
    $colItems = $objwmi.ExecQuery($psdtquery, "WQL", 0x10 + 0x20)

    If IsObj($colitems) Then ; 
        For $objitem In $colitems
            $tdate = $objitem.CreationDate
            Return StringFormat("%s/%s/%s %s:%s:%s",StringLeft($tdate, 4),StringMid($tdate, 5, 2),StringMid($tdate, 7, 2),StringMid($tdate, 9, 2), StringMid($tdate, 11, 2),StringMid($tdate,13, 2))
        Next
    Else
       Return SetError(1,1,0)
    Endif
EndFunc

Thanks for your work :)

sincerly m3rry


www.m3rry.de | nach müde kommt blöd

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