• 大小: 13.68MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-19
  • 语言: C/C++
  • 标签: C语言  

资源简介

使用windows提供的API实现的CPU温度检测,显示在控制台上。使用VS2017版本开发。

资源截图

代码片段和文件信息

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“


#define _WIN32_DCOM
#include 
using namespace std;
#include 
#include 

# pragma comment(lib “wbemuuid.lib“)

int main(int argc char **argv)
{
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);
wcout << “Current CPU Temperature : “ << (vtProp.intVal - 2732) / 10.0 << endl;
cout << endl;
VariantClear(&vtProp);
pclsObj->Release();
}
}
}
pSvc->Release();
}
pLoc->Release();
}
}
}catch (_com_error err){
}
CoUninitialize();
return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-07-20 01:09  CPU_temperature\
     目录           0  2017-07-20 01:08  CPU_temperature\.vs\
     目录           0  2017-07-20 01:08  CPU_temperature\.vs\ConsoleApplication1\
     目录           0  2017-07-20 02:41  CPU_temperature\.vs\ConsoleApplication1\v15\
     文件       33280  2017-07-20 02:42  CPU_temperature\.vs\ConsoleApplication1\v15\.suo
     文件    32489472  2017-07-20 02:42  CPU_temperature\.vs\ConsoleApplication1\v15\Browse.VC.db
     目录           0  2017-07-20 01:08  CPU_temperature\.vs\ConsoleApplication1\v15\ipch\
     目录           0  2017-07-20 01:08  CPU_temperature\.vs\ConsoleApplication1\v15\ipch\CONSOLEAPPLICATION1-ec32c45a\
     文件     3538944  2017-07-20 01:19  CPU_temperature\.vs\ConsoleApplication1\v15\ipch\CONSOLEAPPLICATION1-ec32c45a\CONSOLEAPPLICATION1-822ffee4.ipch
     目录           0  2017-07-20 01:20  CPU_temperature\ConsoleApplication1\
     文件        1339  2017-07-20 01:08  CPU_temperature\ConsoleApplication1.sln
     文件        1792  2017-07-20 01:20  CPU_temperature\ConsoleApplication1\ConsoleApplication1.cpp
     文件        7715  2017-07-20 01:08  CPU_temperature\ConsoleApplication1\ConsoleApplication1.vcxproj
     文件        1326  2017-07-20 01:08  CPU_temperature\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
     目录           0  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\
     目录           0  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\
     文件        1698  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\CL.command.1.tlog
     文件       35674  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\CL.read.1.tlog
     文件        1312  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\CL.write.1.tlog
     文件         198  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\ConsoleApplication1.lastbuildstate
     文件        1458  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\link.command.1.tlog
     文件        3700  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\link.read.1.tlog
     文件         686  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleA.BC979902.tlog\link.write.1.tlog
     文件         236  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleApplication1.log
     文件      113853  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\ConsoleApplication1.obj
     文件     3276800  2017-07-20 01:09  CPU_temperature\ConsoleApplication1\Debug\ConsoleApplication1.pch
     文件       12180  2017-07-20 01:09  CPU_temperature\ConsoleApplication1\Debug\stdafx.obj
     文件      887808  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\vc141.idb
     文件     1003520  2017-07-20 01:21  CPU_temperature\ConsoleApplication1\Debug\vc141.pdb
     文件        1594  2017-07-20 01:08  CPU_temperature\ConsoleApplication1\ReadMe.txt
     文件         223  2017-07-20 01:08  CPU_temperature\ConsoleApplication1\stdafx.cpp
............此处省略6个文件信息

评论

共有 条评论