I need to develop a program in C# find out when was Windows started or shutdown.
Is there a log file that I can read to know Windows start and shutdown times? Or do you have any ideas how to do so?
EDIT :
With the help of Mr. Reed Copsey, the best answer is found under this question.
System.Environment.TickCount
has a 24.8 days limitation.
This is because TickCount
is a millisecond value contained in a signed 32 bits value.
Windows API exposes these two functions:GetTickCount
- returns a 32 bits value - available from Windows 2000GetTickCount64
- returns a 64 bits value - available from Vista/Windows Server 2008
You can use GetTickCount64 this way:
using System.Runtime.InteropServices;
[DllImport("Kernel32.dll")]
static extern long GetTickCount64();
DateTime osStartTime = DateTime.Now - new TimeSpan(10000 * GetTickCount64());
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