Windows 10上的GetTickCount值 [英] GetTickCount values on Windows 10

查看:1148
本文介绍了Windows 10上的GetTickCount值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows API中使用GetTickCount()来获得系统正常运行时间。我想知道系统已经运行了多长时间。

Im trying to use the GetTickCount() in Windows API to get the system uptime. I want to know how long the system has been running.

但是GetTickCount的返回值是非常高的。这段代码给我超过500小时的正常运行时间。

However the return from GetTickCount is insanely high. This code gives me uptime of over 500 hours.

这也适用于GetTickCount64()。

This goes for GetTickCount64() as well.

为什么这个值这么高?

Why is this value so high?

DWORD time_ms = GetTickCount();
DWORD seconds = (time_ms / 1000) % 60;
DWORD minutes = time_ms /(1000*60) % 60;
DWORD hours = time_ms / (1000*60*60);
stringstream ss;
ss << "Hours: ";
ss << hours;
ss << " Minutes: ";
ss << minutes;
ss << " seconds: ";
ss << seconds;
MessageBoxA(0, ss.str().c_str(), "Uptime", 0);

在我运行程序时,我看到它正在正确进行,但不能理解我将如何获得我的桌面的总正常运行时间。

As i run the program I can see that it is progressing correctly, but cannot comprehend how I will get the total uptime for my desktop.

感谢

编辑
我使用 systeminfo在CMD中,并发现系统启动时间实际上是aprox〜500小时前。所以我关闭了电脑和拔掉电源,启动但仍然,系统启动时间有这么高的价值。但是,重新启动计算机使其重置,现在我的代码工作。

Edit: I checked the uptime with "systeminfo" in CMD and found that the "System boot time" was actually aprox ~500hours ago. So I shut down the computer and unplugged the electricity, booted but still,the System boot time had this high value. However, restarting the computer made it reset, and now my code works.

编辑2:
此博客 https://blogs.msdn.microsoft.com/oldnewthing/20141113-00/?p=43623 声明GetTickCount应该用于测量时间间隔比我想要实现的。似乎像我不得不看注册表。

EDIT 2: This blog https://blogs.msdn.microsoft.com/oldnewthing/20141113-00/?p=43623 states that GetTickCount should rather be used for measuring time intervals than what I'm trying to achieve. Seems like I have to look at the registry.

编辑3:

在注册表中找到合适的计数器后,具有相同的值有GetTickCount和类似的函数。似乎关闭在Windows带来了某种休眠。我没有找到任何解决方案。

After finding the right counter in the registry, it has the same value has GetTickCount and similar functions. It seems that shut down in Windows brings it to some sort of hibernation. I have not found any solution to this.

推荐答案

GetTickCount 描述了获取系统的正确方法开始时间:

The documentation for GetTickCount describes the correct way to get the system up-time:


要获取计算机启动后的时间,请检索
系统正常运行时间计数器注册表项
HKEY_PERFORMANCE_DATA中的数据。返回的值是一个8字节的值。有关更多
信息,请参见性能计数器< a>

To obtain the time elapsed since the computer was started, retrieve the System Up Time counter in the performance data in the registry key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. For more information, see Performance Counters

这篇关于Windows 10上的GetTickCount值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆