Click here to Skip to main content
13,005,973 members (105,941 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 6 Sep 2012

Fetch reboot time of remote servers

, 6 Sep 2012
Rate this:
Please Sign up or sign in to vote.
Test whether your remote server rebooted or not from C# code.


This article explains how to test from C# code whether your remote server or personal computer rebooted or not and get the last reboot time. Without logging into a machine we can get the last reboot time of machine from C# code.


I am supporting some remote servers and patches will be installed on these regularly. To maintain the avalability of these servers I need to check the last reboot time, and for this I need to log on to the server manually to get the reboot time by running the below command on CMD.


This takes a lot of time, to log on to the machine and get this.

Using the code

The System.Management class provides us sytem information of remote machines by creating an object as follows.

After creating the ManagementScope object, use this and create a ProcessClass object and call the GetInstances() function, and get the Last Reboot Time property of the machine. Like this we can get the processor speed and hardware capacity.

ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Username = userName;
connOptions.Password = password;
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope;

  manScope= new ManagementScope(string.Format(@"\\{0}\ROOT\CIMV2", 
                serverName), connOptions);

ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_OperatingSystem");
ManagementClass processClass = new ManagementClass(manScope, 
                managementPath, objectGetOptions);

foreach (ManagementObject item in processClass.GetInstances())
    datetime = item["LastBootUpTime"].ToString();

Points of Interest

From this I learnt how to access machine information from C# using the class System.Management.ManagementScope. I am now preparing a UI thing for easy usage of the code.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170628.1 | Last Updated 6 Sep 2012
Article Copyright 2012 by Suraj S Koneri
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid