Oct 29th, 2006, 06:50 AM
#1
Thread Starter
Hyperactive Member
windows uptime
Hi,
I would like to design similiar to the attached screenshot.
How can I find windows uptime? Is there any api for that?
Please give me your inputs.
Thanks in advance.
Kanna.
Attached Images
Oct 29th, 2006, 07:10 AM
#2
Re: windows uptime
this should work:
VB Code:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Debug.Print GetWinUpTime
End Sub
Private Function GetWinUpTime() As String
Dim lSec As Long
lSec = GetTickCount \ 1000
GetWinUpTime = Format$((lSec \ 3600) \ 24, "00 Days ") _
& Format$((lSec \ 3600) Mod 24, "00 Hours ") _
& Format$((lSec Mod 3600) \ 60, "00 Minutes ") _
& Format$((lSec Mod 60), "00 Seconds ")
End Function
bear in mind that GetTickCount wraps round every 49 days
Oct 29th, 2006, 07:50 AM
#3
Oct 29th, 2006, 09:27 AM
#4
Frenzied Member
Re: windows uptime
Originally Posted by
bushmobile
bear in mind that GetTickCount wraps round every 49 days
That can be detected by comparing the new value to the previous value.
If the previous value is higher then a 'wrap' has occurred.
You can then increment a counter to keep track of that.
Oct 29th, 2006, 09:51 AM
#5
Re: windows uptime
Originally Posted by
bushmobile
...bear in mind that GetTickCount wraps round every 49 days
You wouldn't have to worry about it if you use timer and datediff function:
Some of you will say that VB's timer is off a bit and I'll say "So what..."
VB Code:
Option Explicit
Dim sStart As Date
Private Sub Form_Load()
sStart = Now()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim iDays%, iHours%, iMinutes%, iSeconds&
iSeconds = DateDiff("s", sStart, Now)
iMinutes = (iSeconds \ 3600) \ 24
iHours = (iSeconds \ 3600) Mod 24
iDays = (iSeconds Mod 3600) \ 60
Label1.Caption = "elapsed time: " _
& iDays & " days, " _
& iMinutes & " minutes, " _
& iSeconds & " seconds, "
End Sub
Oct 29th, 2006, 09:58 AM
#6
Frenzied Member
Re: windows uptime
You would need to start that right after Windows starts and never shut it down.
Oct 29th, 2006, 10:00 AM
#7
Re: windows uptime
So it may run in the system tray just like your anti virus...
Oct 28th, 2010, 10:44 AM
#8
New Member
Re: windows uptime
if you want to do this in a program without the 49day problem, check the modified date of the windows swap file (usually c:\pagefile.sys )
subtract from current date to get uptime.
Oct 28th, 2010, 11:22 AM
#9
New Member
Re: windows uptime
correction on the sample vb code. the iMinutes and iDays are swapped around,
they should read
Code:
15. iDays = (iSeconds \ 3600) \ 24
16. iHours = (iSeconds \ 3600) Mod 24
17. iMinutes = (iSeconds Mod 3600) \ 60
and the seconds displayed should be str(iSeconds mod 60) not iSeconds,
Code:
22. & str(iSeconds mod 60) & " seconds, "
unless you want a heck of a lot of seconds, in which case the minutes,hours and days would not be needed.
Oct 28th, 2010, 12:03 PM
#10
Re: windows uptime
What's the point of modifying 4 years old and practically dead thread?
Oct 29th, 2010, 03:16 AM
#11
New Member
Re: windows uptime
not so dead i didn't find it usefull :-) thanks for the post. i hadn't noticed the datediff function and just subtracting the numbers gives a 1 day error, where datediff does the job.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width