Download Pelles C here: http://www.smorgasbordet.com/pellesc/
QuoteNtQuerySystemInformation may be altered or unavailable in future versions of Windows.
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.
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);
/* ChatGPT code */
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
int main(void)
{
FILETIME ftNow, ftBootUtc, ftBootLocal;
ULONGLONG now100ns;
ULONGLONG uptimeMs;
ULONGLONG boot100ns;
SYSTEMTIME st;
/* current system time as FILETIME (UTC, 100-ns intervals since 1601) */
GetSystemTimeAsFileTime(&ftNow);
now100ns = ((ULONGLONG)ftNow.dwHighDateTime << 32) | ftNow.dwLowDateTime;
/* milliseconds since system start */
uptimeMs = GetTickCount64(); /* Vista+; returns milliseconds since boot */
/* convert uptime to 100-ns units and subtract */
boot100ns = now100ns - (uptimeMs * 10000ULL);
/* convert back to FILETIME structure */
ftBootUtc.dwLowDateTime = (DWORD)(boot100ns & 0xFFFFFFFF);
ftBootUtc.dwHighDateTime = (DWORD)(boot100ns >> 32);
/* show UTC boot time */
if (FileTimeToSystemTime(&ftBootUtc, &st)) {
printf("Boot time (UTC) : %04u-%02u-%02u %02u:%02u:%02u\n",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
}
/* convert to local time and show */
if (FileTimeToLocalFileTime(&ftBootUtc, &ftBootLocal) &&
FileTimeToSystemTime(&ftBootLocal, &st)) {
printf("Boot time (local): %04u-%02u-%02u %02u:%02u:%02u\n",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
}
return 0;
}
Page created in 0.043 seconds with 15 queries.