Link to home
Start Free TrialLog in
Avatar of Henry_milk
Henry_milk

asked on

CPU temperature&fans speeds

Sorry for my english,but i from brazil.
I need help with urgency,because  i can lose my job !
I need to get cpu temperature e fans speeds,with delphi 6,so,How i do this?

Avatar of jonas78
jonas78

ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
At http://www.workshop-alex.org/Sources/WbemScripting_TLB.pas you can find WbemScripting_TLB.pas for Delphi 7. Maybe with some minor adjustments you can use it in Delphi 6, else just import the type library C:\WINNT\system32\wbem\wbemdisp.tlb in Delphi 6, without letting it generate components for it!
Avatar of Henry_milk

ASKER

I still have  the problem.Anybody?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh yeah, don't forget, this wont work on all computers.  The computer MUST have sensors that are readable by this API.  My Dell Inspiron 8200 laptop doesn't work, but my desktop does (generic brand PC).

Stu
@SJohnson, Yeah, well... I know... The WriteLn() was just as an example. I actually created a console application for that sample code but didn't want to confuse the questioneer with the things needed to initialize the COM system. (If you're using forms and an application, it's done automatically.) Your example works just as well... :-)

Chances are, of course, that his system doesn't have any support to request the fan or temperature information. It's a new feature, actually. For the temperature, you'll need a temperature sensor in your computer or you'll get NO information. For the fan, the same story. Not all fans will return any information about themselves. My brand-less computer at home doesn't support these things so I don't see anything. And neither do my laptop or desktop at home. So I think that quite a few systems don't have these sensors, or else I just picked some systems without these sensors.

AFAIK, there is no API that provides this information...

Some class information that could be useful for you:

class Win32_Fan : CIM_Fan
{
  boolean ActiveCooling;
  uint16 Availability;
  string Caption;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  string Description;
  uint64 DesiredSpeed;
  string DeviceID;
  boolean ErrorCleared;
  string ErrorDescription;
  datetime InstallDate;
  uint32 LastErrorCode;
  string Name;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string Status;
  uint16 StatusInfo;
  string SystemCreationClassName;
  string SystemName;
  boolean VariableSpeed;
};

class Win32_TemperatureProbe : CIM_TemperatureSensor
{
  sint32 Accuracy;
  uint16 Availability;
  string Caption;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  sint32 CurrentReading;
  string Description;
  string DeviceID;
  boolean ErrorCleared;
  string ErrorDescription;
  datetime InstallDate;
  boolean IsLinear;
  uint32 LastErrorCode;
  sint32 LowerThresholdCritical;
  sint32 LowerThresholdFatal;
  sint32 LowerThresholdNonCritical;
  sint32 MaxReadable;
  sint32 MinReadable;
  string Name;
  sint32 NominalReading;
  sint32 NormalMax;
  sint32 NormalMin;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  uint32 Resolution;
  string Status;
  uint16 StatusInfo;
  string SystemCreationClassName;
  string SystemName;
  sint32 Tolerance;
  sint32 UpperThresholdCritical;
  sint32 UpperThresholdFatal;
  sint32 UpperThresholdNonCritical;
};

At MSDN you can find more specific information about these classes...
IEnumVariant isn't in D6.

I try to compile it on D6 and get 6 different errors.
this is an interesting thread, havnt got a clue how to answer it but I thought I'd try it out ... having problems installing that component - how do i do it  ?
I put the code of RunMe in a  button,but don't see anything.Maybe model of my mother,I try on 3 computer different and don't returns any information.
SJohnson,you could explain me what do you do for alex's code worked with you?
IEnumVariant can be found in the ActiveX control and exists in this unit in both Delphi 5 and Delphi 7...

My code is not fully complete. To make it complete, create a new console application and save it as ShowInfo.dpr. Then make it look like this:

program ShowInfo;
{$APPTYPE CONSOLE}
uses Windows, SysUtils, Classes, ActiveX, ComObj, WbemScripting_TLB;
function NextItem( var Enum: IEnumVARIANT; const riid: TGUID; out ppObject ): Boolean;
var
  OleProperty: OleVariant;
  NumProp: LongWord;
begin
  try
    Result := Succeeded( Enum.Next( 1, OleProperty, NumProp ) ) and ( NumProp > 0 ) and Succeeded( IDispatch( OleProperty ).QueryInterface( riid, ppObject ) );
  except
    Result := False;
    IUnknown( ppObject ) := nil;
  end;
end;
procedure RunMe;
const
  //sQuery = 'select * from Win32_Fan';
  sQuery = 'select * from Win32_TemperatureProbe';
var
  Enum: IEnumVariant;
  Item: SWbemObject;
  PropEnum: IEnumVariant;
  Prop: SWbemProperty;
begin
  Enum := CoSWbemLocator.Create.ConnectServer( '', 'root\cimv2', '', '', '', '', 0, nil ).ExecQuery( sQuery, 'WQL', wbemFlagBidirectional, nil )._NewEnum as IEnumVariant;
  while NextItem( Enum, SWBemObject, Item ) do begin
    WriteLn( string( Item.Path_.Path ) );
    PropEnum := Item.Properties_._NewEnum as IEnumVariant;
    while NextItem( PropEnum, SWBemProperty, Prop ) do begin
      try
        WriteLn( '+ ', string( Prop.Name ), ': ', Trim( VarToStr( Prop.Get_Value ) ) );
      except on E: Exception do WriteLn( '+ ', E.Message );
      end;
    end;
  end;
end;
begin
  RunMe;
  Write('Press <Enter> to quit');
  ReadLn;
end. // <--- A dot, not semicolon!

This is the whole project. No forms, no separate units. Just a simple console application. Compile it, run it and see the information appear onscreen, if your system is able to produce it... If not, it will be pretty empty.
Alex,sorry,but the line " WriteLn( '+ ', string( Prop.Name ), ': ', Trim( VarToStr( Prop.Get_Value ) ) );"
have a error"Undeclared identifier :'VarToStr'
I'm using Delphi 6.
I get the same error in D7 pro ?
VarToStr is the the Variants unit.

Try this.  My GUI version of Alex's code.

http://users.on.net/jonstu/hardwareinfo.zip (220K)
Yes, i had the same error on D7

I didn't, which is why I posted a fully working version above.  Has anyone who couldn't previously get it working tried the source I posted?
Dear Expert Comment
This code {2004-10-26} does not work at Windows 7.
What can we do there?
Dear Expert Comment
This code {2004-10-26} does not work at Windows 7.
What can we do there?