Get Up Time Of a Computer

This code sample is used to get the up time of a computer


This Simple Code Written in VB.net to get the total time from when the computer is switched on



Module Module1

Public Function getUptime() As String
Dim time As String = String.Empty
time += Math.Round(Environment.TickCount / 86400000) & " days, "
time += Math.Round(Environment.TickCount / 3600000 Mod 24) & " hours, "
time += Math.Round(Environment.TickCount / 120000 Mod 60) & " minutes, "
time += Math.Round(Environment.TickCount / 1000 Mod 60) & " seconds."
Return time
End Function

Sub Main()
Console.WriteLine(getUptime())
End Sub

End Module


Comments

Guest Author: Kyle06 Oct 2012

How can this be applied to a list of computers i have defined in a .txt?

Guest Author: noone18 Mar 2013

This will not work for computer running over 24.9 days. The int value that stores the Environment.TickCount will roll over.

Guest Author: dHROOb28 Feb 2014

yeepee... it works ...

Guest Author: dHROOb28 Feb 2014

For VB.NET (I use VB.NET 2008 Express Edition)

---------------------------------code---------------

'write this in a button click event

Dim time As String = String.Empty
time += Math.Round(Environment.TickCount / 86400000) & " days, "
time += Math.Round(Environment.TickCount / 3600000 Mod 24) & " hours, "
time += Math.Round(Environment.TickCount / 120000 Mod 60) & " minutes, "
time += Math.Round(Environment.TickCount / 1000 Mod 60) & " seconds."
MsgBox(time)
-----------------------------------------end of code-------



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: