PDA

Click to See Complete Forum and Search --> : System Uptime


Paul M
May 1st, 2007, 02:18 AM
Here is a simple way of getting your Systems Uptime, the code also includes how to update it automatically :D

Form Contains the following code:
Option Explicit

Private Sub Form_Load()
Label1.Caption = Uptime
TimerID = SetTimer(Me.hWnd, 0, 1000, AddressOf TimerExec)
End Sub


Module Contains the following code:
Option Explicit

Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public TimerID As Long

Public Sub TimerExec()
Form1.Label1.Caption = Uptime
End Sub

Public Function Uptime() As String
Dim lngSeconds As Long, lngDays As Long, lngHours As Long, lngMins As Long
lngSeconds = GetTickCount / 1000
lngDays = Int(lngSeconds / 86400)
lngSeconds = lngSeconds Mod 86400
lngHours = Int(lngSeconds / 3600)
lngSeconds = lngSeconds Mod 3600
lngMins = Int(lngSeconds / 60)
lngSeconds = lngSeconds Mod 60
Uptime = "Uptime = " & lngDays & " Days " & lngHours & " Hours " & lngMins & " Minutes " & lngSeconds & " Seconds"
End Function