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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to tell how long your comptuers been running? 1

Status
Not open for further replies.

Hawkeye123456

Programmer
May 5, 2000
24
0
0
US
I want to know how long my computers has been running. I know I can do it by reading form a file that is created when the system starts that has the time and date that the system started on, but I want to know if there is a built in way to tell. Like an API call or somthing like that.
 
Hawkeye1234546,

hmmmm, an interesting thought. Perhaps MS thought such a value would never get large enough to be of interest to anyone?

I don't know of any existing process for MS O.S.s It is pretty easy to conceive of one, just do a tiny program which puts Now() at boot up time into a "file", and another which - when called, retrieves this and 'calculates' the diff. This could get fooled by clock change(s), but would save the overhead of an ongoing interrupt timer.

MichaelRed
There is never time to do it right but there is always time to do it over
 
There is a way ive seen it and did the code, but i forget dammit
it is an api call
its in milliseconds(the return)
and some math to convert to hours
more to come....

-Tryp
 
gotta be possible, in Start ->Accessories ->System Tools in Win98, there is the System Info app that tells you the uptime of your pc, along with everything else...build off that if you can
 
In WIN9X, you can use the date and time from the (I think hidden) file C:\SYSTEM.1ST. That file is created each time the system boots...
 
Here is one (slightly verbose) way of doing this, with a millisecond resolution, that works on all versions of Windows (for NT/2000/XP check out Performance Monitoring on MSDN for an alternative method). Note that clock rolls over to 0 after 49.7 days. Also, the API call used has a resolution of approx +/-55 milliseconds.
[tt]
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long

Public Function GetUpTime() As String
Dim UpTime As Long

Dim UpDays As Long
Dim UpHours As Long
Dim UpMinutes As Long
Dim UpSeconds As Long
Dim UpMSecs As Long
UpTime = GetTickCount

UpDays = UpTime \ (60& * 60& * 24& * 1000&)
UpTime = UpTime - UpDays * 60& * 60& * 24& * 1000&

UpHours = UpTime \ (60& * 60& * 1000&)
UpTime = UpTime - UpHours * 60& * 60& * 1000&

UpMinutes = UpTime \ (60& * 1000&)
UpTime = UpTime - UpMinutes * 60& * 1000&

UpSeconds = UpTime \ 1000
UpMSecs = UpTime Mod 1000

GetUpTime = CStr(UpDays) + " Days " + CStr(UpHours) + " Hours " + CStr(UpMinutes) + " Minutes " + CStr(UpSeconds) + " Seconds " + CStr(UpMSecs) + " MSeconds"
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top