Консультация № 109972
18.11.2007, 12:50
0.00 руб.
0 1 1
здравствуйте многоуважаемые эксперты. Вопрос такого плана, как средствами делфи замерить температуру процессора и материнской платы. Заранее благодарен.

Обсуждение

давно
Профессионал
153662
1070
19.11.2007, 17:06
общий
это ответ
Здравствуйте, Jakoni! Я использовал для этой цели WMI запросы, но к сожелению этот код на моей материнке не хочет работать, нет необходимых провайдеров. В приложении исходник.

Приложение:
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, OleServer, WbemScripting_TLB, ActiveX, ExtCtrls;type TForm1 = class(TForm) Button1: TButton; ListView1: TListView; SWbemLocator1: TSWbemLocator; Bevel1: TBevel; StatusBar1: TStatusBar; Label1: TLabel; Label2: TLabel; ListView2: TListView; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } procedure ShowProp(SProp: ISWbemProperty); procedure GetProp(Win32ClassName: string; ListNum: integer); public { Public declarations } end;var Form1: TForm1; ListItem: TListItem;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin GetProp(‘Win32_Fan‘, 1);end;procedure TForm1.GetProp(Win32ClassName: string; ListNum: integer);var Service: ISWbemServices; ObjectSet: ISWbemObjectSet; SObject: ISWbemObject; PropSet: ISWbemPropertySet; SProp: ISWbemProperty; PropEnum, Enum: IEnumVariant; TempObj: OleVariant; Value: Cardinal; Column: TListColumn; ListView: TListView;begin if ListNum = 1 then ListView:= ListView1 else ListView:= ListView2; StatusBar1.SimpleText:= ‘ in progress‘; ListView.Items.BeginUpdate; ListView.Items.Clear; Service:= SWbemLocator1.ConnectServer(‘.‘, ‘root\CIMV2‘, ‘‘, ‘‘, ‘‘, ‘‘, 0, nil); SObject:= Service.Get(Win32ClassName, wbemFlagUseAmendedQualifiers, nil); ObjectSet:= SObject.Instances_(0, nil); Enum:= (ObjectSet._NewEnum) as IEnumVariant; if (Enum.Next(1, TempObj, Value) = S_FALSE) then begin MessageBox(0, PChar(‘Отсутствует провайдер или требуемое устройство.‘), PChar(Form1.Caption), MB_OK); ListView.Items.EndUpdate; StatusBar1.SimpleText:= ‘ Done‘; exit; end; while (Enum.Next(1, TempObj, Value) = S_OK) do begin SObject:= IUnknown(TempObj) as SWBemObject; PropSet:= SObject.Properties_; PropEnum:= (PropSet._NewEnum) as IEnumVariant; ListItem:= ListView.Items.Add; // начинаю перебирать свойства StatusBar1.SimpleText:= StatusBar1.SimpleText + ‘.‘; while (PropEnum.Next(1, TempObj, Value) = S_OK) do begin SProp:= IUnknown(TempObj) as SWBemProperty; if ListView.Items.Count = 1 then begin Column:= ListView.Columns.Add; Column.Width:= 100; Column.Caption:= SProp.Name; end; ShowProp(SProp); end; end; { while } ListView.Items.EndUpdate; StatusBar1.SimpleText:= ‘ Done‘;end;procedure TForm1.ShowProp(SProp: ISWbemProperty);var StrValue: string; Count: Cardinal;begin StrValue:= ‘‘; if VarIsNull(SProp.Get_Value) then StrValue:= ‘<empty>‘ else case SProp.CIMType of//******************************************************************// wbemCimtypeUint8, wbemCimtypeSint8, wbemCimtypeUint16, wbemCimtypeSint16, wbemCimtypeUint32, wbemCimtypeSint32, wbemCimtypeSint64: if VarIsArray(SProp.Get_Value) then begin if VarArrayHighBound(SProp.Get_Value, 1) > 0 then for Count:= 1 to VarArrayHighBound(SProp.Get_Value, 1) do StrValue:= StrValue + ‘ ‘ + IntToStr(SProp.Get_Value[Count]); end else StrValue:= IntToStr(SProp.Get_Value);//******************************************************************// wbemCimtypeReal32, wbemCimtypeReal64: StrValue:= FloatToStr(SProp.Get_Value);//******************************************************************// wbemCimtypeBoolean: if SProp.Get_Value then StrValue:= ‘True‘ else StrValue:= ‘False‘;//******************************************************************// wbemCimtypeString, wbemCimtypeUint64: if VarIsArray(SProp.Get_Value) then begin if VarArrayHighBound(SProp.Get_Value, 1) > 0 then for Count := 1 to VarArrayHighBound(SProp.Get_Value, 1) do StrValue:= StrValue + ‘ ‘ + SProp.Get_Value[Count]; end else StrValue:= SProp.Get_Value;//******************************************************************// wbemCimtypeDatetime: StrValue:= SProp.Get_Value;//******************************************************************// wbemCimtypeReference: begin// end;//******************************************************************// wbemCimtypeChar16: StrValue:= ‘16-bit char‘;//******************************************************************// wbemCimtypeObject: StrValue:= ‘CIM Object‘;//******************************************************************// else MessageBox(0, PChar(‘Unknown type‘), PChar(Form1.Caption), MB_OK); end; {case} if ListItem.Caption = ‘‘ then ListItem.Caption := StrValue else ListItem.SubItems.Add(StrValue);end;procedure TForm1.Button2Click(Sender: TObject);begin GetProp(‘Win32_TemperatureProbe‘, 2);end;end.
Об авторе:
Мои программы со статусом freeware для Windows на моём сайте jonix.ucoz.ru

Форма ответа