You can try to use Environment.TickCount to determine how long ago a machine was started. But Environment.TickCount returns a 32-bit signed integer which can overflow for systems that stay up for days at a time.
To avoid this overflow problem, you can query the "System Up Time" performance counter:
public TimeSpan SystemUpTime()
{
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
// You've got to call this twice. First time it returns 0 and the second time it returns the real info.
upTime.NextValue();
return TimeSpan.FromSeconds(upTime.NextValue());
}
Caveat: if your software runs with limited privileges you may not be able to query the performance counter. For example, I run my website on a shared server, and it's not allowed to query this performance counter :-(.
This tip is based on a newsgroup posting by Stoitcho Goutsev.
| Title | Date |
| Node.js + Express: How to Block Requests by User-Agent Headers | January 7, 2026 |
| Vault 3 is Now Available for Windows on ARM Machines! | December 13, 2025 |
| Vault 3: How to Include Outline Text in Exported Photos | October 26, 2025 |
| .NET Public-Key (Asymmetric) Cryptography Demo | July 20, 2025 |
| Raspberry Pi 3B+ Photo Frame | June 17, 2025 |
| EBTCalc (Android) Version 1.53 is now available | May 19, 2024 |
| Vault 3 Security Enhancements | October 24, 2023 |