How to access laptop battery temperature in Windows?

thinkinnight picture thinkinnight · Oct 17, 2013 · Viewed 9.8k times · Source

I want to get the battery temperature in Windows, and I have tried DeviceIoControl function (http://msdn.microsoft.com/en-us/library/aa372698(v=vs.85).aspx) on the BatteryTemperature.

I have tried other parameter like BatterySerialNumber, and it returns the serial number, but while I want to get the temperature, the function returns FALSE. And GetLastError returns S_FALSE.

My enviroment is Win7 Enterprise SP1, I developed on VS2008+SP1, total C++ code, my laptop is HP Elitebook 2570p. Can anyone give some suggestions on this topic. I have searched Google and donot find any help topic, or should I write some driver code to get the temperature? Or this laptop battery doesnot support this function?

Thanks very much.

PS. If there are any other tech which can get the temperature is welcome, not only in C++.

Answer

Oleg Korzhukov picture Oleg Korzhukov · Feb 20, 2017

S_FALSE returned by GetLastError is also just 1, which is also ERROR_INVALID_FUNCTION. Extract from MSDN:

If the particular type of data requested is not available for the current battery, then ERROR_INVALID_FUNCTION is returned.

This means your battery has no temperature sensor or manufacturer who written the battery driver decided not to provide this information to Windows.