Geting the system uptime on Windows
Re: Geting the system uptime on Windows
I've rebooted the system several times since then so the number there is way off.
Re: Geting the system uptime on Windows
I see. That's weird, then, since Microsoft is supplying the info.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Geting the system uptime on Windows
There was a post once about a bit more tricky way to get the system uptime: http://www.purebasic.fr/english/viewtop ... 12&t=39017
Just do something liketo see the formatted output.
Just do something like
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))
Re: Geting the system uptime on Windows
Most impressive! Is this in milliseconds, counting from 0 after a reboot?
Re: Geting the system uptime on Windows
No, it is in 100 nanoseconds since boot. That's why the division by 10000000 to get to seconds.
Re: Geting the system uptime on Windows
Hi !
First, Happy New Year !
Now I'm no expert, but where is the difference with your procedures and:
I think it's the accuracy? Or what?
Thank you
First, Happy New Year !
Now I'm no expert, but where is the difference with your procedures and:
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 "----------------------"

Thank you

Sorry for my english
! (Windows Xp, Vista and Windows 7, Windows 10)

Re: Geting the system uptime on Windows
Well, the second call is later of course, but measured in seconds I get the same result:
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))
Re: Geting the system uptime on Windows
pcfreak wrote:Code: Select all
Procedure.s S2Str(time.q) time=time

Re: Geting the system uptime on Windows
Ups, just ignore that ;)
Re: Geting the system uptime on Windows
Here is an adaptaions of PB's way. I use Net statistics workstation to get the up time.
Works pretty much instantly :
Works pretty much instantly :
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()
----
R Tape loading error, 0:1
R Tape loading error, 0:1
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: Geting the system uptime on Windows
Why shell to cmd 1st? why not just call net.exe ?
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()
Re: Geting the system uptime on Windows
But only works if the system is English.