diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 092b5af2f..a11d8c5c0 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -134,14 +134,12 @@ static PyObject *TimeoutAbandoned; */ static PyObject * psutil_boot_time(PyObject *self, PyObject *args) { -#if (_WIN32_WINNT >= 0x0600) // Windows Vista ULONGLONG uptime; -#else - double uptime; -#endif time_t pt; FILETIME fileTime; - long long ll; + ULONGLONG ll; + HINSTANCE hKernel32; + psutil_GetTickCount64 = NULL; GetSystemTimeAsFileTime(&fileTime); /* @@ -157,33 +155,26 @@ psutil_boot_time(PyObject *self, PyObject *args) { and 01-01-1601, from time_t the divide by 1e+7 to get to the same base granularity. */ -#if (_WIN32_WINNT >= 0x0600) // Windows Vista ll = (((ULONGLONG) -#else - ll = (((LONGLONG) -#endif (fileTime.dwHighDateTime)) << 32) + fileTime.dwLowDateTime; pt = (time_t)((ll - 116444736000000000ull) / 10000000ull); - // GetTickCount64() is Windows Vista+ only. Dinamically load - // it at runtime. We may have used + // GetTickCount64() is Windows Vista+ only. Dynamically load + // GetTickCount64() at runtime. We may have used // "#if (_WIN32_WINNT >= 0x0600)" pre-processor but that way // the produced exe/wheels cannot be used on Windows XP, see: // https://github.com/giampaolo/psutil/issues/811#issuecomment-230639178 if (psutil_GetTickCount64 != NULL) { // Windows >= Vista - uptime = psutil_GetTickCount64() / (ULONGLONG)1000.00f; - return Py_BuildValue("K", pt - uptime); + uptime = psutil_GetTickCount64() / 1000ull; } else { // Windows XP. // GetTickCount() time will wrap around to zero if the // system is run continuously for 49.7 days. - psutil_debug("Windows < Vista; using GetTickCount() instead of " - "GetTickCount64()"); - uptime = GetTickCount() / (LONGLONG)1000.00f; - return Py_BuildValue("L", pt - uptime); + uptime = (ULONGLONG)GetTickCount() / 1000ull; } + return Py_BuildValue("K", pt - uptime); }