获取进程启动时间,在与当前系统时间相减就能得到进程运行时间。
获取进程启动时间代码:#Include <Date.au3>
$Pid=ProcessExists("Explorer.exe")
MsgBox(0,"","'Explorer.exe' 进程启动时间: " & _GetProcessTimes($Pid))
Func _GetProcessTimes($_PID)
$_PID=ProcessExists($_PID)
If $_PID=0 Then Return ""
$_Return=DllCall("Kernel32.dll","hwnd","OpenProcess","dword",0x0400,"int",False,"dword",$_PID)
$_time1=DllStructCreate($tagFILETIME)
$_time2=DllStructCreate($tagFILETIME)
$_time3=DllStructCreate($tagFILETIME)
$_time4=DllStructCreate($tagFILETIME)
$_Return=DllCall("Kernel32.dll","int","GetProcessTimes","hwnd",$_Return[0],"ptr",DllStructGetPtr($_time1),"ptr",DllStructGetPtr($_time2),"ptr",DllStructGetPtr($_time3),"ptr",DllStructGetPtr($_time4))
DllCall("Kernel32.dll","int","CloseHandle","hwnd",$_Return[0])
$_LocalFileTime=_Date_Time_FileTimeToLocalFileTime(DllStructGetPtr($_time1))
$aDate=_Date_Time_FileTimeToArray($_LocalFileTime)
Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d", $aDate[2], $aDate[0], $aDate[1], $aDate[3], $aDate[4], $aDate[5])
EndFunc
|