2

I'm expanding an application which need to accommodate Windows from XP and up. The program is in C and need to get the time of the last boot of the computer. For Vista and up there is a function getTickCount64() which I linked below.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx

The problem is that for XP this function is unavailable and the 32 bits version of this function getTickCount() only counts ~49 days then loops around because of the number of milliseconds that can fit in a 32 bit unsigned integer.

I can't use command line tools like systeminfo, WMIC, Powershell or net statistics workstation.

Is there a timestamp anywhere on the system where this information is kept appart from being deducted from a difference of the system time and getTickCount function ? And how could I retrieve it from my C program ?

Polar Bear
  • 354
  • 3
  • 15
  • 1
    Is there any reason why you don't want to use WMI directly from C? – Roger Lipscombe Mar 14 '16 at 20:24
  • 1
    By putting a small utility in the start folder which writes the time in seconds to a file. – Weather Vane Mar 14 '16 at 20:36
  • Why would you want to support XP in a new application? – Jonathan Potter Mar 14 '16 at 20:36
  • WMI is probably your best option as Roger suggests. But if you just want a simple hack for XP, try calling GetProcessTimes on the system process, process ID 4. (But if you do this, you **must** check the version of Windows first and use this approach **only** when running on XP. On more recent versions you should use GetTickCount64() instead. There's no guarantee that a hack that works for XP will keep working for newer versions.) – Harry Johnston Mar 14 '16 at 20:44
  • The application is for security purposes and needs to be as discrete as possible so no other process created or files created. As for XP the application is not new and some of or clients still use it... Would make my job much more easier if they didn't ! – Polar Bear Mar 14 '16 at 21:19
  • How is this a duplicate ?? I'm asking for a fix for windows XP and you redirect to a question for Windows 10 using the functions I cannot use... – Polar Bear Mar 15 '16 at 12:43
  • Did you even read the answers in the other question? One answer explains how to get the system uptime using a Performance counter. You can subtract that from the current clock time. My answer explains how to use `NtQuerySystemInformation()` instead to obtain the exact boot up timestamp (the same one that Task Manager uses) and it works on XP (I use it in my own code). – Remy Lebeau Mar 15 '16 at 15:25
  • I saw the answer but when I found on MSDN that it was an opaque structure for a randomiser I didn't go any further. But how do you know for sure that this structure contains what you say it does ? Is there documentation for this ? – Polar Bear Mar 15 '16 at 18:10

0 Answers0