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.
Printable View
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.
this should work:bear in mind that GetTickCount wraps round every 49 daysVB 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
Nice code Bush!!
That can be detected by comparing the new value to the previous value.Quote:
Originally Posted by bushmobile
If the previous value is higher then a 'wrap' has occurred.
You can then increment a counter to keep track of that.
You wouldn't have to worry about it if you use timer and datediff function:Quote:
Originally Posted by bushmobile
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
You would need to start that right after Windows starts and never shut it down.
So it may run in the system tray just like your anti virus...
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.
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,
unless you want a heck of a lot of seconds, in which case the minutes,hours and days would not be needed.Code:22. & str(iSeconds mod 60) & " seconds, "
What's the point of modifying 4 years old and practically dead thread?
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.