Get windows sensors by Windows Sensors API
under VS2010 & Windows 7 sdk.

// wSensors.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include


#include


#include


#include


#include

#include

#include

#pragma comment(lib, "Sensorsapi.lib") int getSensors(int *num) { ISensorManager *pSensorManager; ISensorCollection *pSensorColl; ISensor *pSensor; ULONG uCount; HRESULT hr= S_OK; hr = CoCreateInstance(CLSID_SensorManager,NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pSensorManager)); if (FAILED(hr)) { printf("\n[-] CoCreateInstance() fail!"); return 0; } hr = pSensorManager->GetSensorsByCategory(SENSOR_CATEGORY_ALL, &pSensorColl); if (FAILED(hr)) { printf("\n[-] GetSensorsByCategory() fail!"); printf("\n[-] No any sensors were found!"); return 0; } hr = pSensorColl->GetCount(&uCount); if (FAILED(hr)) { printf("\n[-] GetCount fail, "); return 0; } for (ULONG i=0; i

GetAt(i, &pSensor))) { BSTR fName; pSensor->GetFriendlyName(&fName); printf("[I] %S\n", fName); SysFreeString(fName); } } *num = (int)uCount; return uCount; } int _tmain(int argc, _TCHAR* argv[]) { int num; int ret = 0; CoInitialize(0); if (getSensors(&num)!=0) { printf("Sensors: %d", num); }else { ret = 1; } CoUninitialize(); return ret; }