# Viewing System Uptime

In the early days of Windows NT 3.51 and 4.0, it wasn’t uncommon for servers to reboot or need to be rebooted on a regular basis. Applications were not as well behaved as they are today and the operating system wasn’t as stable. This changed with Windows 2000, when unexpected failures became much less common. But there were still a lot of hotfixes and patches to install on a regular basis, most of which required reboots. Hopefully Windows Server 2003 will continue the upward trend in availability and further reduce the number of reboots that are required.

It is a good idea to pay attention to the uptime on your servers to make sure their availability jives with what you think it should be. Perhaps a server rebooted due to a blue screen or even worse, because another administrator (or attacker!) did something they shouldn’t have. Looking at system uptime is the poor man’s availability monitor. You may even want to create a script that runs at system startup on your servers, which can serve as a notification mechanism anytime your servers reboot.

Using a command-line interface

All three of the following commands display the system uptime:

> psinfo \\ | findstr Uptime
> srvinfo \\ | findstr /c:"Up Time"
> systeminfo /s  | findstr /c:"Up Time"

Using VBScript

' This code prints system uptime for a host.
' ------ SCRIPT CONFIGURATION ------
strComputer = "."   ' e.g., rallen-srv01
' ------ END CONFIGURATION ---------
set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
for each objOS in colOS
objWMIDateTime.Value = objOS.LastBootUpTime
Wscript.Echo "System Up Time: " & objWMIDateTime.GetVarDate
next