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
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 2000
GetTickCount64
- 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());