
这样做涉及哪些API调用?
您可以分享哪些好的代码示例?
解决方法 您可以使用WMI类 Win32_TemperatureProbe和 Win32_Fan,来自delphi,您必须使用Component-> import Component-> import type library-> Next->“选择库” – > Next->将单元添加到项目 – >导入Microsoft WMIScripting V1.x库. ;完.
看到这段代码.只是一个简单的例子.
program GetWMI_Info;{$APPTYPE CONSolE}uses ActiveX,Variants,SysUtils,WbemScripting_TLB in '..\..\..\documents\RAD Studio.0\imports\WbemScripting_TLB.pas';procedure ShowTemperatureInfo();var WMIServices: ISWbemServices; Root : ISWbemObjectSet; Item : Variant; I : Integer;begin { http://msdn.microsoft.com/en-us/library/aa394493%28VS.85%29.aspx The Win32_TemperatureProbe WMI class represents the propertIEs of a temperature sensor (electronic thermometer). Most of the information that the Win32_TemperatureProbe WMI class provIDes comes from SMBIOS. Real-time readings for the CurrentReading property cannot be extracted from SMBIOS tables. For this reason,current implementations of WMI do not populate the CurrentReading property. The CurrentReading property's presence is reserved for future use. } Writeln('Temperature Info'); Writeln('----------------'); WMIServices := CoSWbemLocator.Create.ConnectServer('.','root\cimv2','',nil); Root := WMIServices.Execquery('Select * FROM Win32_TemperatureProbe','WQL',nil); for I := 0 to Root.Count - 1 do begin Item := Root.ItemIndex(I); Writeln('Accuracy '+VarToStr(Item.Accuracy)); Writeln('Availability '+VarToStr(Item.Availability)); Writeln('Caption '+Item.Caption); Writeln('Config Manager Error Code '+VarToStr(Item.ConfigManagerErrorCode)); Writeln('Config Manager User Config '+VarToStr(Item.ConfigManagerUserConfig)); Writeln('Creation Class name '+VarToStr(Item.CreationClassname)); Writeln('Current Reading '+VarToStr(Item.CurrentReading)); Writeln('Description '+VarToStr(Item.Description)); Writeln('Device ID '+VarToStr(Item.deviceid)); Writeln('Error Cleared '+VarToStr(Item.ErrorCleared )); Writeln('Error Description '+VarToStr(Item.ErrorDescription)); Writeln('Install Date '+VarToStr(Item.InstallDate)); Writeln('Is linear '+VarToStr(Item.Islinear)); Writeln('Last Error Code '+VarToStr(Item.LastErrorCode)); Writeln('Lower Threshold Critical '+VarToStr(Item.LowerThresholdCritical)); Writeln('Lower Threshold Fatal '+VarToStr(Item.LowerThresholdFatal)); Writeln('Lower Threshold NonCritical '+VarToStr(Item.LowerThresholdNonCritical)); Writeln('Max Readable '+VarToStr(Item.MaxReadable)); Writeln('Min Readable '+VarToStr(Item.MinReadable)); Writeln('name '+VarToStr(Item.name)); Writeln('Nominal Reading '+VarToStr(Item.NominalReading)); Writeln('normal Max '+VarToStr(Item.normalMax)); Writeln('normal Min '+VarToStr(Item.normalMin )); Writeln('PNP Device ID '+VarToStr(Item.PNPdeviceid)); Writeln('Power Management CapabilitIEs '+VarToStr(Item.PowerManagementCapabilitIEs)); Writeln('Power Management Supported '+VarToStr(Item.PowerManagementSupported)); Writeln('Resolution '+VarToStr(Item.Resolution)); Writeln('Status '+VarToStr(Item.Status)); Writeln('Status Info '+VarToStr(Item.StatusInfo)); Writeln('System Creation Class name '+VarToStr(Item.SystemCreationClassname)); Writeln('System name '+VarToStr(Item.Systemname)); Writeln('Tolerance '+VarToStr(Item.Tolerance)); Writeln('Upper Threshold Critical '+VarToStr(Item.UpperThresholdCritical)); Writeln('Upper Threshold Fatal '+VarToStr(Item.UpperThresholdFatal)); Writeln('Upper Threshold NonCritical '+VarToStr(Item.UpperThresholdNonCritical)); Writeln(''); end;end;procedure ShowcpuFanInfo();var WMIServices: ISWbemServices; Root : ISWbemObjectSet; Item : Variant; I : Integer;begin { http://msdn.microsoft.com/en-us/library/aa394146%28VS.85%29.aspx The Win32_Fan WMI class represents the propertIEs of a fan device in the computer system. For example,the cpu cooling fan. } Writeln('cpu FAN Info'); Writeln('----------------'); WMIServices := CoSWbemLocator.Create.ConnectServer('.',nil); Root := WMIServices.Execquery('Select * FROM Win32_Fan',nil); for I := 0 to Root.Count - 1 do begin Item := Root.ItemIndex(I); Writeln('ActiveCooling '+VarToStr(Item.ActiveCooling)); Writeln('Availability '+VarToStr(Item.Availability)); Writeln('Caption '+VarToStr(Item.Caption)); Writeln('Config Manager ErrorCode '+VarToStr(Item.ConfigManagerErrorCode)); Writeln('Config Manager UserConfig '+VarToStr(Item.ConfigManagerUserConfig)); Writeln('Creation Classname '+VarToStr(Item.CreationClassname)); Writeln('Description '+VarToStr(Item.Description)); Writeln('DesiredSpeed '+VarToStr(Item.DesiredSpeed)); Writeln('deviceid '+VarToStr(Item.deviceid)); Writeln('ErrorCleared '+VarToStr(Item.ErrorCleared)); Writeln('ErrorDescription '+VarToStr(Item.ErrorDescription)); Writeln('InstallDate '+VarToStr(Item.InstallDate)); Writeln('LastErrorCode '+VarToStr(Item.LastErrorCode)); Writeln('name '+VarToStr(Item.name)); Writeln('PNPdeviceid '+VarToStr(Item.PNPdeviceid)); Writeln('PowerManagement CapabilitIEs '+VarToStr(Item.PowerManagementCapabilitIEs)); Writeln('PowerManagement Supported '+VarToStr(Item.PowerManagementSupported)); Writeln('Status '+VarToStr(Item.Status)); Writeln('StatusInfo '+VarToStr(Item.StatusInfo)); Writeln('SystemCreation Classname '+VarToStr(Item.SystemCreationClassname)); Writeln('Systemname '+VarToStr(Item.Systemname)); Writeln('VariableSpeed '+VarToStr(Item.VariableSpeed)); Writeln(''); end;End;begin try CoInitialize(nil); ShowTemperatureInfo(); ShowcpuFanInfo(); Readln; CoUninitialize; except on E:Exception do Begin CoUninitialize; Writeln(E.Classname,': ',E.Message); Readln; End; end;end. 总结 以上是内存溢出为你收集整理的如何编写Delphi程序来控制CPU风扇速度并监控温度?全部内容,希望文章能够帮你解决如何编写Delphi程序来控制CPU风扇速度并监控温度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)