To know when computer was turned on

tdi

Progress Fan
Hi there, greetings from Mexico.

I just wanted to know if someone had this same need, sometime back.

I want to log the time the computer was turned on, and then, when the user logs in the system, (I already can do this, but no when it was turned on)

Any clue?

Thannks

Octavio Olguin

(also posted on dotr.com)
 

bendaluz2

Member
Possibly

I presume from the fact this is posted in the API section, that you want an API type solution to this. I am sure there is one out there that does it, but that will probably give you the time that windows started or the user logged into windows rather than when the computer was turned on. Maybe this is what you really want (i dont know). If you want to know when the computer was turned on, the best way I can think of is to put something like this in autoexec.bat

echo > c:\timeon.dat

then, when your application starts up, get the date and time for that file, and you should get the time the computer was switched on ( to within a few seconds at least)

Hope it helps
:)
 

Dan Dragut

New Member
GetTickCount function (kernel32.dll) retrieves the number of milliseconds that have elapsed since the system was started, but you have to consider that the timer is wrapping around to zero every 50 days.
You can also read the System Up Time counter to retrieve the time elapsed since the computer was started.

HTH,
 
Top