Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How long the system is running since last boot

API Functions

How long the system is running since last boot

by  AirCon  Posted    (Edited  )
This function will determine how long the system has been running since the last time we start up (boot) the system.

Notes: the return value is DWORD (32bit unsigned long). So it will wrap around (reset) to zero if the system run continuously for 49.7 days.

Enjoy!

[color blue]
[color green]*** Example[/color]
#Define CR chr(13)

Local lcOldEscape
Local lnDays, lnHours, lnMinutes, lnSeconds

lcOldEscape = set('escape')
Set escape off
Set decimals to 3
Do while (lastkey() != 27)
GetSystemElapsedTime(@lnDays, @lnHours, @lnMinutes, @lnSeconds)
Wait 'Windows has been running for: ' + CR + CR + ;
alltrim(transform(lnDays, '99 days')) + CR + ;
alltrim(transform(lnHours, '99 hours')) + ', ' + ;
alltrim(transform(lnMinutes, '99 minutes')) + ', ' + ;
alltrim(transform(lnSeconds, '99.999 seconds')) + CR + CR + ;
'Press ESC to close...' window nowait noclear
= inkey(0.1, 'HM')
enddo
Set decimals to
Set escape &lcOldEscape
Wait clear
** Clear Dlls GetTickCount


[color green]*** The function[/color]
Procedure GetSystemElapsedTime(tnDays, tnHours, tnMinutes, tnSeconds)
Local lnTick

Declare Long GetTickCount in Kernel32

lnTick = GetTickCount()
tnHours = int(lnTick / 3600000)
If (tnHours > 23)
tnDays = int(tnHours/24)
tnHours = mod(tnHours, 24)
else
tnDays = 0
endif
lnTick = mod(lnTick, 3600000)
tnMinutes = int(lnTick / 60000)
tnSeconds = Mod(lnTick, 60000) / 1000
EndProc
[color green]*****************
*** End function
*****************[/color]
[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top