VB获取电脑CPU温度

mengkun   发布于 2016年07月22日   阅读次数: 2557   

Tag: VB CPU 温度

'添加一个Timer Interval 值设为100
'添加一个Label
Public Function GetCPUTemp() As Double
    Dim i As Integer
    Dim mCPU As Variant
    Dim u As Variant
    Dim s As String
    Set mCPU = GetObject("WINMGMTS:{impersonationLevel=impersonate}!root\wmi").ExecQuery("SELECT CurrentTemperature From MSAcpi_ThermalZoneTemperature")
    For Each u In mCPU
        s = s & u.CurrentTemperature
    Next
    Set mCPU = Nothing
    GetCPUTemp = (s - 2732) / 10
End Function
Private Sub Timer1_Timer()
    Label1.Caption = "当前CPU的温度为:" & GetCPUTemp() & "℃"
End Sub