TN AppSvr 109 Obtain last server bootup time
Description
This tech note describes an option for determining when a computer was last restarted or booted up.
- Author: Joseph Hefner
- Published: 01/02/2015
- Application Server
Instructions
Create a UDA or Field Attribute of type String to hold the date and time of the last system bootup. In the example below, I have created a UDA called BootUpTime:
Next Create a Script that triggers on startup and utilizes the System.Environment.TickCount as below:
dim mc as System.Management.ManagementClass;
mc = new System.Management.ManagementClass("Win32_OperatingSystem");
dim Env as System.Environment;
dim tc as integer;
dim t as System.TimeSpan;
tc = System.Environment.TickCount;
t = System.TimeSpan.FromMilliseconds(tc);
Me.BootUpTime = System.DateTime.Now.Subtract(t);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Upon the next bootup, the UDA you created called BootUpTime should be populated with the time of the last boot. You can check this value in Object Viewer as below: