How to get Environment.TickCount on Remote Server

  • Thread starter Thread starter Robert Barish
  • Start date Start date
R

Robert Barish

Sub Page_Load(source as Object, e as EventArgs)

Dim ts as TimeSpan = TimeSpan.FromMilliseconds(Environment.TickCount)
ltlUptime.Text = "ServerName has been up for:<br>" & _
ts.Days & " days, " & ts.Hours & " hours, " & _
"and " & ts.Minutes & " minutes."

End Sub


Above is sample code to get the TickCount for the local server. Is there a
way to get the TickCount for a Remote Server. I am trying to develop an
ASPX page that will monitor multiple remote web servers and I would like to
be able to get the TickCount for these remote computers.
 
I tried this code:

Imports System.Diagnostics

Dim perfSysUpTime As New PerformanceCounter("System", "System Up Time")
ts = TimeSpan.FromSeconds(perfSysUpTime.NextValue())
minutesUp = ts.Minutes
hoursUp = ts.Hours
daysUp = ts.Days
lblSysUptime.Text = ts.Days & " days, " & ts.Hours & " hours, " & _
"and " & ts.Minutes & " minutes."

but "perfSysUpTime.NextValue()" always returns 0.0.
 
I fixed it.

You have to call "perfSysUpTime.NextValue()" before you actually use it. So the right code should now look like this:

Dim perfSysUpTime As New PerformanceCounter("System", "System Up Time")
perfSysUpTime.NextValue()
ts = TimeSpan.FromSeconds(perfSysUpTime.NextValue())
minutesUp = ts.Minutes
hoursUp = ts.Hours
daysUp = ts.Days
lblSysUptime.Text = ts.Days & " days, " & ts.Hours & " hours, " & _
"and " & ts.Minutes & " minutes."
 
Back
Top