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;
}
#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);
}
Page created in 0.077 seconds with 15 queries.