user-0 提问: c/c++查看cpu温度、硬盘温度、内存温度。求完整代码

回复:
user: user-1
content: cpu温度怎么获取求代码

user: user-0
content: 您好谢谢您，您这个我有。谢谢您

user: user-0
content: 内存温度怎么获取？

user: user-2
content: 希望这个对你有点帮助 http://zhaofuguang.blog.163.com/blog/static/3787330320111129553376/

user: user-0
content: 可以查看自己机器，到别人就不行，我用的2010.

user: user-0
content: // q1.cpp : 定义控制台应用程序的入口点。 //  #include "stdafx.h"  #include <afxcoll.h> #include<cstring> #define _WIN32_DCOM #include <iostream> using namespace std; #include <comdef.h> #include <Wbemidl.h>  # pragma comment(lib, "wbemuuid.lib")  int _tmain(int argc, _TCHAR* argv[]) { 	CString m_strTest;  	CoInitializeEx(0,COINIT_MULTITHREADED); 	try  	{ 		if(SUCCEEDED(CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL)))  		{ 			IWbemLocator *pLoc=NULL; 			if(SUCCEEDED(CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator,(LPVOID *)&pLoc))) 			{ 				IWbemServices *pSvc=NULL; 				if(SUCCEEDED(pLoc->ConnectServer(_bstr_t(L"ROOT\\WMI"),NULL,NULL,0,NULL,0,0,&pSvc))) 				{ 					if(SUCCEEDED(CoSetProxyBlanket(pSvc,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL,RPC_C_AUTHN_LEVEL_CALL,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE))) 					{ 						IEnumWbemClassObject* pEnumerator=NULL; 						if(SUCCEEDED(pSvc->ExecQuery(bstr_t("WQL"),bstr_t("SELECT * FROM MSAcpi_ThermalZoneTemperature"),WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumerator))) 						{ 							IWbemClassObject *pclsObj; 							ULONG uReturn=0; 							while(pEnumerator) 							{ 								pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);  								if(0==uReturn) 								break; 								VARIANT vtProp; 								VariantInit(&vtProp); 								pclsObj->Get(L"CurrentTemperature", 0, &vtProp, 0, 0);     								VARIANT vtProp1; 								VariantInit(&vtProp1); 								pclsObj->Get(L"Win32_BIOS", 0, &vtProp1, 0, 0);    								VARIANT vtProp2; 								VariantInit(&vtProp2); 								pclsObj->Get(L" Win32_Processor", 0, &vtProp2, 0, 0);  								VARIANT vtProp3; 								VariantInit(&vtProp3); 								pclsObj->Get(L"VendorSpecific", 0, &vtProp3, 0, 0); 								 								//BSTR bstrInfoBIOS = (L"Select * from Win32_BIOS"); 								//wmigetsysteminformation(bstrInfoBIOS); 								wcout<<vtProp1.intVal<<"dsds"<<vtProp2.intVal<<"dsd"<< vtProp2.cVal<<"dsd"<< vtProp3.intVal<< endl; 								wcout << "Current CPU Temperature : " << (vtProp.intVal - 2732)/10.0 << endl; 								 								VariantClear(&vtProp); 								pclsObj->Release(); 							} 						} 					} 					pSvc->Release(); 				} 				pLoc->Release(); 			} 		} 	} catch (_com_error err) { }  	HRESULT hres;  	hres =  CoInitializeEx(0, COINIT_MULTITHREADED);   	hres =  CoInitializeSecurity( 		NULL,  		-1,                          // COM authentication 		NULL,                        // Authentication services 		NULL,                        // Reserved 		RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication  		RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation   		NULL,                        // Authentication info 		EOAC_NONE,                   // Additional capabilities  		NULL                         // Reserved 		);   	IWbemLocator *pLoc = NULL;  	hres = CoCreateInstance( 		CLSID_WbemLocator,              		0,  		CLSCTX_INPROC_SERVER,  		IID_IWbemLocator, (LPVOID *) &pLoc);   	 	IWbemServices *pSvc = NULL;  	 	hres = pLoc->ConnectServer( 		_bstr_t(L"ROOT\\WMI"), // Object path of WMI namespace 		NULL,                    // User name. NULL = current user 		NULL,                    // User password. NULL = current 		0,                       // Locale. NULL indicates current 		NULL,                    // Security flags. 		0,                       // Authority (e.g. Kerberos) 		0,                       // Context object  		&pSvc                    // pointer to IWbemServices proxy 		);  	hres = CoSetProxyBlanket( 		pSvc,                        // Indicates the proxy to set 		RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx 		RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx 		NULL,                        // Server principal name  		RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx  		RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx 		NULL,                        // client identity 		EOAC_NONE                    // proxy capabilities  		);   	IEnumWbemClassObject* pEnumerator = NULL; 	hres = pSvc->ExecQuery( 		bstr_t("WQL"),  		bstr_t("SELECT * FROM MSStorageDriver_ATAPISmartData"), 		WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,  		NULL, 		&pEnumerator);  	  	int nTemperature = 0; 	int nTotalTime = 0;  	IWbemClassObject *pclsObj; 	ULONG uReturn = 0;  	while (pEnumerator) 	{ 		HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,  			&pclsObj, &uReturn);  		if(0 == uReturn) 		{ 			break; 		}  		VARIANT vtProp; 		VariantInit(&vtProp);  		// Get the value of the VendorSpecific property 		hr = pclsObj->Get(L"VendorSpecific", 0, &vtProp, 0, 0);  		//if (vtProp.vt == VT_ARRAY|VT_UI1 ) 		{ 			SAFEARRAY *pIn; 			pIn = vtProp.parray; 			VARTYPE vt; 			UINT dim; 			SafeArrayGetVartype(pIn,&vt);    //获得数据类型 			dim = SafeArrayGetDim(pIn);    //获得维数 			long LBound;                           //下界 			long UBound;                           //上界 			SafeArrayGetLBound(pIn,1,&LBound);    //获得下界 			SafeArrayGetUBound(pIn,1,&UBound);   //获得上界 			BYTE *pdata = new BYTE[UBound-LBound+1]; 			ZeroMemory(pdata,UBound-LBound+1);  			BYTE *buf; 			SafeArrayAccessData(pIn, (void **)&buf); 			memcpy(pdata,buf,UBound-LBound+1); 			SafeArrayUnaccessData(pIn);  			BYTE* pTemp = pdata+2; 			for(int i=2;i<UBound-LBound+1;i+=12) 			{ 				pTemp = pdata+i; 				if (*pTemp == 0xc2) 				{ 					//Beep(1000,200); 					nTemperature = *(pTemp+5); 				}  				if (*pTemp == 0x09) 				{ 					//Beep(1000,200); 					nTotalTime = (*(pTemp+5)) + (*(pTemp+6)<<8); 				}  			} 		}  		//m_strTest.Format("硬盘已经使用了 %d 个小时 ， 现在的温度是 %d C",nTotalTime,nTemperature); 		 		wcout<<nTotalTime<<"硬盘现在的温度是"<<nTemperature<<"c";  		VariantClear(&vtProp); 	}      CoUninitialize(); getchar(); 	return 0; }

user: user-0
content: 您好；您说的是linux系统，谢谢您，我想要windows的。谢谢。

user: user-3
content: 它是个工具，你需要自行在线安装： Ubuntu #apt-get install lm-sensors Centos.Fedora:#yum install lm-sensors

user: user-3
content: sensors(1)  //传感器                  Linux User's Manual                   sensors(1)  NAME        sensors - print sensors information  SYNOPSIS        sensors [ options ] [ chips ]        sensors -s [ chips ]        sensors --bus-list  DESCRIPTION        sensors is used to show the current readings of all sensor chips.        sensors  -s        file.        sensors --bus-list   OPTIONS        -c config-file               Specify  a configuration file. If no file is specified, the lib‐               sensors default configuration file is used. Use  `-c  /dev/null'               to temporarily disable this default configuration file.         -h     Print a help text and exit.         -s     Evaluate  all  `set'  statements  in  the configuration file and               exit. You must be `root' to do this. If this  parameter  is  not               specified, no `set' statement is evaluated.         -A     Do not show the adapter for each chip.         -u     Raw output. This mode is only meant for debugging.         -v     Print the program version and exit.         -f     Print the temperatures in degrees Fahrenheit instead of Celsius.         --bus-list               Generate bus statements suitable for using in sensors.conf. Such               bus statements are only needed if you have several chips sharing               the  same  address  on  different buses of the same type. As bus               numbers are usually not guaranteed to be  stable  over  reboots,               these  statements  let  you refer to each bus by its name rather               than numbers.

user: user-4
content: 可以写个shell脚本，程序中调用这个脚本，例如一个简单的脚本文件（linux下）  #!/bin/bash  #获取CPU温度 sensors | grep CPUTIN | awk '{print $2}' | cut -c 2-5 #获取系统温度 sensors | grep SYSTIN | awk '{print $2}' | cut -c 2-5

user: user-0
content: 账号:zhao4zhong1昵称:zhao4zhong1已关注 博客空间 最新帖子: 1.C/C++论坛领取赠书需要发站内短... 2.个人意见：不检查scanf函数返回... 3.散分＋普及DOS命令行知识 更多 >>zhao4zhong1 zhao4zhong1 等级：Blank   更多勋章  #1 得分：0  回复于： 2013-10-10 16:32:54    WMI ？

user: user-0
content: wmi,使用c++或c写的

user: user-5
content: WMI ？