如何获取当前的CPU频率和硬盘名称 [英] How Do I Get Current Cpu Frequency And Harddisk Name

查看:171
本文介绍了如何获取当前的CPU频率和硬盘名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用WMI的情况下在内核模式或用户模式下获取当前cpu频率和硬盘名称....谢谢

解决方案

你可以获得cpu频率来自注册表,或者您可以自己计算。

HKEY_LOCAL_MACHINE \ HARDWARE \DESCRIPTION\System\CentralProcessor \ 0 \ ~MHZ



您可以在大致相同的位置获取有关硬盘的信息:

HKEY_LOCAL_MACHINE \HARDWARE \DEVICEMAP \Scsi \Scsi Port 0 \Scsi Bus 0 \Target Id 0 \逻辑单位ID 0





为了自己计算速度,您可以使用以下代码。返回的值是以MHz为单位的速度。除以1000得到GHz。



 无符号  int  hiPart,loPart; 
unsigned __ int64 CycleCount()
{
__ int64 结果;
asm(
rdtsc \ n
mov%eax,_loPart \ n
mov%edx,_hiPart
);
result = hiPart;
结果<< = 32 ;
result | = loPart;
返回结果;
}
int GetCpuSpeed()
{
unsigned __ int64 start,stop,elapsed;
unsigned int total;
start = CycleCount();
睡眠( 1000 );
stop = CycleCount();
逝去=停止 - 开始;
total =( unsigned )(停止/ 1000000);
返回总计;
}





在我的情况下,注册表返回2494(Mhz),上面的代码片段返回值2,492 (兆赫)。


how do i get current cpu frequency and harddisk name in kernel mode or user mode without use WMI....thanks

解决方案

You can get the cpu freq from the registry, or you can calculate it yourself.
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\~MHZ

You can get info about the harddisk in roughly the same place:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0


In order to compute the speed yourself, you can use the following code. The value returned is the speed in MHz. Divide by 1000 to get GHz.

unsigned int hiPart, loPart;
unsigned __int64 CycleCount()
{
    __int64 result;
   asm(
    "rdtsc\n"
    "mov %eax, _loPart\n"
    "mov %edx, _hiPart"
   );
   result = hiPart;
   result <<= 32;
   result |= loPart;
   return result;
}
int GetCpuSpeed()
{
   unsigned __int64 start, stop, elapsed;
   unsigned int total;
   start = CycleCount();
   Sleep(1000);
   stop = CycleCount();
   elapsed = stop - start;
   total = (unsigned)(stop/1000000);
   return total;
}



In my case, the registry returns "2494" (Mhz) and the above snippet returns a value of 2,492 (Mhz).


这篇关于如何获取当前的CPU频率和硬盘名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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