Inspirate from
http://masm32.com/board/index.php?msg=140972 (http://masm32.com/board/index.php?msg=140972)
I might fix this later.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define NTSTATUS LONG
typedef struct _SYSTEM_TIMEOFDAY_INFORMATION
{
LARGE_INTEGER BootTime; // Number of 100-nanosecond intervals since the system was started.
LARGE_INTEGER CurrentTime; // The current system date and time.
LARGE_INTEGER TimeZoneBias; // Number of 100-nanosecond intervals between local time and Coordinated Universal Time (UTC).
ULONG TimeZoneId; // The current system time zone identifier.
ULONG Reserved; // Reserved
ULONGLONG BootTimeBias; // Number of 100-nanosecond intervals between the boot time and Coordinated Universal Time (UTC).
ULONGLONG SleepTimeBias; // Number of 100-nanosecond intervals between the sleep time and Coordinated Universal Time (UTC).
} SYSTEM_TIMEOFDAY_INFORMATION, *PSYSTEM_TIMEOFDAY_INFORMATION;
#define SystemTimeOfDayInformation 3
// enum SYSTEM_INFORMATION_CLASS
//NTSTATUS WINAPI NtQuerySystemInformation(int SystemInformationClass,
// PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
typedef int (WINAPI NTQUERYSYSTEMINFORMATION)(int SystemInformationClass,
PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
typedef NTQUERYSYSTEMINFORMATION *LNTQUERYSYSTEMINFORMATION;
// FILETIME SYSTEMTIME
void __cdecl WinMainCRTStartup(void)
{
HANDLE hLib;
static LNTQUERYSYSTEMINFORMATION NtQuerySystemInformation;
SYSTEM_TIMEOFDAY_INFORMATION stodi;
FILETIME ft;
SYSTEMTIME st;
char szBuf[50];
hLib = LoadLibrary("ntdll.dll");
NtQuerySystemInformation = (LNTQUERYSYSTEMINFORMATION)GetProcAddress(hLib, "NtQuerySystemInformation");
NtQuerySystemInformation(SystemTimeOfDayInformation, &stodi, sizeof(stodi), 0);
(*(LONGLONG*)&stodi.BootTime) -= (*(LONGLONG*)&stodi.TimeZoneBias);
ft.dwLowDateTime = ((LARGE_INTEGER*)&stodi.BootTime)->LowPart;
ft.dwHighDateTime = ((LARGE_INTEGER*)&stodi.BootTime)->HighPart;
FileTimeToSystemTime(&ft, &st);
wsprintf(szBuf, "Date: %04d-%02d-%02d\nTime: %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond);
MessageBox(0, szBuf, "Boot time", MB_OK);
ExitProcess(0);
}
Hi Timo,
Keep up the nice work.
Hi Timo,
Another method to get the boot time is to use the GetTickCount64 API function.
Quote from: Vortex on November 09, 2025, 08:22:44 PMAnother method to get the boot time is to use the GetTickCount64 API function.
Works only since Vista.
This is quite short.
NtQuerySystemInformation(SystemTimeOfDayInformation, &stodi, sizeof(stodi), 0);
// (*(LONGLONG*)&stodi.BootTime) -= (*(LONGLONG*)&stodi.TimeZoneBias);
stodi.BootTime.QuadPart -= stodi.TimeZoneBias.QuadPart;
(*(LONGLONG*)&ft) = (*(LONGLONG*)&stodi.BootTime);
FileTimeToSystemTime(&ft, &st);
Hi Timo,
There is also the GetTickCount function. The documentation states that :
QuoteNtQuerySystemInformation may be altered or unavailable in future versions of Windows.
https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntquerysysteminformation