How to get Windows boot time?

后端 未结 1 691
抹茶落季
抹茶落季 2021-01-14 13:25

How can I get Windows boot time in C++ with some WinAPI functions? I am currently using the command \"systeminfo\", but I\'m looking for a more proper solution.

相关标签:
1条回答
  • 2021-01-14 13:35

    I've checked at how Task Manager does it, and turns out it uses the ZwQuerySystemInformation(SystemTimeOfDayInformation, ...) function, which receives the SYSTEM_TIMEOFDAY_INFORMATION structure.

    typedef struct _SYSTEM_TIMEOFDAY_INFORMATION {
        LARGE_INTEGER BootTime;
        LARGE_INTEGER CurrentTime;
        LARGE_INTEGER TimeZoneBias;
        ULONG TimeZoneId;
        ULONG Reserved;
        ULONGLONG BootTimeBias;
        ULONGLONG SleepTimeBias;
    } SYSTEM_TIMEOFDAY_INFORMATION, *PSYSTEM_TIMEOFDAY_INFORMATION;
    

    (source)

    BootTime is what you're looking for.

    For something more documented, I think GetTickCount64 will do.

    0 讨论(0)
提交回复
热议问题