Windows: UptimePID()

Share your advanced PureBasic knowledge/code with the community.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Windows: UptimePID()

Post by sec »

Windows: UptimePID(), the function will return the uptime in second of pid (process)

Code: Select all

Procedure.i UptimePID(pid.i) ; second
  creation.FILETIME 
  exit.FILETIME 
  kernel.FILETIME 
  user.FILETIME 
  stime.SYSTEMTIME
  ltime.SYSTEMTIME; 
  h = OpenProcess_(#PROCESS_QUERY_INFORMATION, #False, pid)  
  If h
    GetProcessTimes_(h,creation,exit,kernel,user) 
    FileTimeToSystemTime_(creation,stime);
    SystemTimeToTzSpecificLocalTime_(#Null,stime,ltime);
    ProcedureReturn Date() - Date(ltime\wYear,ltime\wMonth,ltime\wDay, ltime\wHour, ltime\wMinute, ltime\wSecond)
  EndIf
  ProcedureReturn 0
EndProcedure
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Windows: UptimePID()

Post by RSBasic »

Thank you for sharing.
Image
Image
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Windows: UptimePID()

Post by BarryG »

Good code, thank you. I have many uses for this.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Windows: UptimePID()

Post by Kwai chang caine »

Works great on W7 X86
Thanks for sharing this usefull tip 8)
ImageThe happiness is a road...
Not a destination
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Windows: UptimePID()

Post by ar-s »

Amazing.
Great possibilities. Thanks
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
Post Reply