我如何获得Cpu和Harddisk的温度...... [英] How Do I Get Cpu's And Harddisk's Temperature....

查看:98
本文介绍了我如何获得Cpu和Harddisk的温度......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。我试着通过wmi得到它...但是faild .......我用了C ...



.i try to get it by wmi ...but faild.......i used C...

#define _WIN32_WINNT 0x0400 
#define _WIN32_DCOM 

#include <stdio.h> 
#include <tchar.h> 
#include <windows.h> 
#include <wbemidl.h> 
#pragma comment(lib,"wbemuuid.lib")

VOID GetCPUTemperatureInfo()
{
	// result code from COM calls 
	HRESULT hr = 0; 

	// COM interface pointers 
	IWbemLocator         *locator  = NULL; 
	IWbemServices        *services = NULL; 
	IEnumWbemClassObject *results  = NULL; 

	// BSTR strings we'll use (http://msdn.microsoft.com/en-us/library/ms221069.aspx) 
	BSTR resource = SysAllocString(L"ROOT\\CIMV2"); 
	BSTR language = SysAllocString(L"WQL"); 
	BSTR query    = SysAllocString(L"SELECT * FROM Win32_TemperatureProbe"); 

	// initialize COM 
	hr = CoInitializeEx(0, COINIT_MULTITHREADED); 
	hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); 

	// connect to WMI 
	hr = CoCreateInstance(&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (LPVOID *) &locator); 
	hr = locator->lpVtbl->ConnectServer(locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services); 

	// issue a WMI query 
	hr = services->lpVtbl->ExecQuery(services, language, query, WBEM_FLAG_BIDIRECTIONAL, NULL, &results); 

	// list the query results 
	if (results != NULL) { 
		IWbemClassObject *result = NULL; 
		ULONG returnedCount = 0; 

		// enumerate the retrieved objects 
		while((hr = results->lpVtbl->Next(results, WBEM_INFINITE, 1, &result, &returnedCount)) == S_OK) { 
			VARIANT CurrentReading;

			// obtain the desired properties of the next result and print them out 
			hr = result->lpVtbl->Get(result, L"CurrentReading", 0, &CurrentReading, 0, 0); 

			printf(L"CurrentReading: %d\n", CurrentReading); 

			// release the current result object 
			result->lpVtbl->Release(result); 
		}
	}

	// release WMI COM interfaces 
	results->lpVtbl->Release(results); 
	services->lpVtbl->Release(services); 
	locator->lpVtbl->Release(locator); 

	// unwind everything else we've allocated 
	CoUninitialize(); 

	SysFreeString(query); 
	SysFreeString(language); 
	SysFreeString(resource); 

	return;
}

推荐答案

您不能保证以这种方式(或任何其他方式)获得CPU或HDD温度 - 它完全取决于主板和硬盘驱动器的制造商是否提供了符合规范的硬件和驱动程序,并确实将其提供给系统。由于这不是强制性的,许多制造商根本不这样做,你得到的价值毫无意义。
You can't guarantee to get CPU or HDD temperatures in that way (or any other) - it depends entirely on whether the manufacturer of the motherboard and HDD have provided the hardware and drivers that conform to the spec and do provide it to the system at all. As this is not compulsory, many manufacturers do not do it at all, and the values you get are meaningless.


这篇关于我如何获得Cpu和Harddisk的温度......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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