Possible Duplicate:
Displaying the build date
How to know when was Windows started or shutdown?
for my purposes I am writing a C# executable that will calculate the difference in time (minutes) from the time right now and the time the server was last rebooted.
What I am currently doing now is capturing and parsing the output from cmd -> "net stats server" and creating a new DateTime
object then comparing that with DateTime.Now
with a TimeSpan
object.
Is there a cleaner way to do this without the use of 3rd party downloads? I am scared that not all date formats from "net stats server" are in the format that I will expect.
**edit my bad, this is a duplicate, but for what it is worth my solution was using this:
float ticks = System.Environment.TickCount;
Console.WriteLine("Time Difference (minutes): " + ticks / 1000 / 60);
Console.WriteLine("Time Difference (hours): " + ticks / 1000 / 60 / 60);
Console.WriteLine("Time Difference (days): " + ticks / 1000 / 60 / 60 / 24);
Task Manager Instead of showing the last boot time, it shows the uptime of the system since the last boot. To open Task Manager, simply use the Ctrl + Shift + Esc keyboard shortcut. Navigate to the Performance tab. The system uptime will be displayed near the bottom of the window.
You can use the systeminfo command to get the last boot time of the computer. In the above command, systeminfo uses /S parameter to specify the server name. It returns the last boot time for the remote computer.
Just enter eventvwr in the run dialog (which can be called by pressing Win + R ). Under Windows Logs > System look for events from the "Kernel-Power". This will also show if the system unexpectedly restarted by a blue screen and show events prior to it.
this answer should help you. If you want to know when the system was last rebooted just take the uptime value and subtract it from the current date/time
code from linked answer
public TimeSpan UpTime {
get {
using (var uptime = new PerformanceCounter("System", "System Up Time")) {
uptime.NextValue(); //Call this an extra time before reading its value
return TimeSpan.FromSeconds(uptime.NextValue());
}
}
}
you can do this with powsershell using the WMI in it
$wmi = Get-WmiObject -Class Win32_OperatingSystem -Computer "RemoteMachineName"
$wmi.ConvertToDateTime($wmi.LastBootUpTime)
Something like this...
A very useful link if you decide to go with this route and want to know more on powershell using WMI http://www.powershellpro.com/powershell-tutorial-introduction/powershell-wmi-methods/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With