Retrieving the date/time when any user last turned on the Computer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to know if there is function in VB.NET that returns the date and
time someone last turned on/off the computer? I'm more interested in knowing
this on a non-networked computer. Maybe there is already an .exe in the
windows operating system that performs this task.

How can I get the above requested info?
 
Hi Keith,

A while back I wrote a small uptime app which allowed me to enter the name
of a computer on my network and request it's uptime. It did this by
enumerating the processes on the target machine until it found the SYSTEM
process, and then using it's StartTime property to determine how long the
system had been running. Take a look at the Process object for more
details, as it's even simpler if all you want is the local system's uptime.

Cheers,
Alex Clark
 
Keith,
The "System Up Time" performance counter has the "time elapsed since the
computer was started", you can use something like to retrieve its value:

Dim counter As New PerformanceCounter("System", "System Up Time")
Dim seconds As Double = counter.NextValue()
seconds = counter.NextValue()

Dim startTime As DateTime = DateTime.Now.AddSeconds(-seconds)

Note the two calls to NextValue are needed, due to the way
PerformanceCounter works.

I was thinking Environment.TickCount would be an alternative, however its
value is limited to 24.9 hours...

I'm not sure if there is a "better" Win32 API, as the GetTickCount API
references the "System Up Time" counter...

Not sure if the above would be supported on Windows 98.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top