Is there a simple way to get a system's uptime using C#?
Using /proc/uptimeThe first number is the total number of seconds the system has been up. The second number is how much of that time the machine has spent idle, in seconds. On multi core systems (and some Linux versions) the second number is the sum of the idle time accumulated by each CPU.
Right-click the Windows taskbar and select Task Manager. Once Task Manager is open, click the Performance tab. Under the Performance tab, you will find the label Uptime.
To check your computer uptime using Command Prompt, use these steps: Open Start. Search for Command Prompt, right-click the top result, and click the Run as administrator option. Type the following command to query the device's last boot time and press Enter: wmic path Win32_OperatingSystem get LastBootUpTime.
For Windows Home Server, XP, or Server 2003, go to Start >> Run and type: cmd, then hit Enter. At the command prompt, type: net stats srv then hit Enter. You'll see the line Statistics Since – this shows the date and time that your system has been running.
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()); } } }
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