VB 获取CPU温度示例
0 Reply , Posted in 程序代码 on 2017 08, 2017
VERSION 5.00Begin VB.Form Form1
Caption = "获取CPU温度"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "获取"
Height = 495
Left = 1440
TabIndex = 0
Top = 600
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Download by http://www.NewXing.com
Private Sub Command1_Click()
MsgBox "CPU 溫度 : " & CPU_Temperature & " °C"
End Sub
Private Function CPU_Temperature() As Integer
Dim WMIsvc As Object
Dim CltItems As Object, CltItem As Object
Dim Q As String
Set WMIsvc = GetObject("winmgmts:\\.\root\WMI")
Q = "SELECT * FROM MSAcpi_ThermalZoneTemperature"
Set CltItems = WMIsvc.ExecQuery(Q, , 48)
For Each CltItem In CltItems
CPU_Temperature = CltItem.CurrentTemperature
Next
CPU_Temperature = (CPU_Temperature - 2732) / 10
Set CltItem = Nothing
Set CltItems = Nothing
Set WMIsvc = Nothing
End Function