Re: Geting the system uptime on Windows
Posted: Sun Nov 21, 2010 3:28 pm
I've rebooted the system several times since then so the number there is way off.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Procedure.s S2Str(time.q)
time=time
d.f=time/86400
d=Round(d,0)
h.f=time/3600-(d*24)
h=Round(h,0)
m.f=time/60-(d*1440)-(h*60)
m=Round(m,0)
s.f=time-(d*86400)-(h*3600)-(m*60)
s=Round(s,0)
string.s=""
If d>0 : string+Str(d)+"days " : EndIf
If h>0 : string+Str(h)+"houres " : EndIf
If m>0 : string+Str(m)+"minutes " : EndIf
If s>0 : string+Str(s)+"seconds" : EndIf
ProcedureReturn string
EndProcedure
Debug S2Str(IntQ(GetInterruptTime() / 10000000))
Code: Select all
Temp.f=ElapsedMilliseconds()/1000
Debug Temp
H=Int(Temp/3600)
Debug "Heures : "+Str(H) ; Nombre d'heures...
M=Int(Temp/60)-H*60
Debug "Minutes : "+Str(M) ; Nombre de minutes
Debug "----------------------"
Code: Select all
;Public domain, created by Rescator.
;Based on info found at http://www.dcl.hpi.uni-potsdam.de/research/WRK/?p=34
CompilerIf #PB_Compiler_Processor=#PB_Processor_x86
Procedure.q GetInterruptTime()
!_GetInterruptTime_Repeat_Start:
!MOV edx,dword [7FFE0008h+4]
!MOV eax,dword [7FFE0008h]
!MOV ecx,dword [7FFE0008h+8]
!CMP edx,ecx
!JNE _GetInterruptTime_Repeat_Start
ProcedureReturn
EndProcedure
CompilerElse
Procedure.q GetInterruptTime()
!MOV qword rdx,7FFE0008h
!_GetInterruptTime_Repeat_Start:
!MOVSXD rax,dword [rdx+4]
!MOVSXD rbx,dword [rdx]
!MOVSXD rcx,dword [rdx+8]
!CMP rax,rcx
!JNE _GetInterruptTime_Repeat_Start
!SAL rax,32
!ADD rax,rbx
ProcedureReturn
EndProcedure
CompilerEndIf
Procedure.s S2Str(time.q)
time=time
d.f=time/86400
d=Round(d,0)
h.f=time/3600-(d*24)
h=Round(h,0)
m.f=time/60-(d*1440)-(h*60)
m=Round(m,0)
s.f=time-(d*86400)-(h*3600)-(m*60)
s=Round(s,0)
string.s=""
If d>0 : string+Str(d)+"days " : EndIf
If h>0 : string+Str(h)+"houres " : EndIf
If m>0 : string+Str(m)+"minutes " : EndIf
If s>0 : string+Str(s)+"seconds" : EndIf
ProcedureReturn string
EndProcedure
Debug S2Str(IntQ(GetInterruptTime() / 10000000))
Debug S2Str(IntQ(ElapsedMilliseconds() / 1000))
pcfreak wrote:Code: Select all
Procedure.s S2Str(time.q) time=time
Code: Select all
Procedure.s UpTime() ; For XP or higher. Pretty much instant now :) ~ em_uk
p=RunProgram("cmd.exe","/c net statistics workstation ","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
If p
While ProgramRunning(p) : o$+ReadProgramString(p)+#CRLF$ : Wend : CloseProgram(p)
up$=Trim(Mid(o$,FindString(o$,"Statistics since",1)+16)) : up$=Left(up$,FindString(up$,#CRLF$,1)-1)
EndIf
ProcedureReturn up$
EndProcedure
Debug UpTime()
Code: Select all
Procedure.s UpTime() ; For XP or higher. Pretty much instant now :) ~ em_uk
p=RunProgram("net.exe","statistics workstation ","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
If p
While ProgramRunning(p) : o$+ReadProgramString(p)+#CRLF$ : Wend : CloseProgram(p)
up$=Trim(Mid(o$,FindString(o$,"Statistics since",1)+16)) : up$=Left(up$,FindString(up$,#CRLF$,1)-1)
EndIf
ProcedureReturn up$
EndProcedure
Debug UpTime()