InPowerS.Net

 找回密碼
 註冊
搜索
查看: 2226|回復: 0

VB.Net 使用 WMI ( Windows Management Instrumentation ) 來取得 CPU 溫度

[複製鏈接]
發表於 2008-12-26 13:13:23 | 顯示全部樓層 |閱讀模式
VB.Net 使用 WMI ( Windows Management Instrumentation ) 來取得 CPU 溫度

<< VB.Net >>

請先加入參考 System.Management

Imports System
Imports System.Management

Public Class Form1


Private Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click



Dim CPUtprt As Integer = CPU_Temperature()



If CPUtprt >= 100 Then


MessageBox.Show("CPU
溫度: " & CPUtprt.ToString & " °C" & ControlChars.CrLf & _
"溫度破錶嚕! 快準備煎蛋囉! " & ControlChars.CrLf & _
"或開啟自動灑水系統降溫喔!")

Else


MessageBox.Show("CPU
溫度: " & CPU_Temperature() & " °C")

End If



End Sub



'
取得CPU 溫度

Private Function CPU_Temperature() As Integer


Dim Q As String = "Select * From MSAcpi_ThermalZoneTemperature"


Dim mos As New ManagementObjectSearcher("root\WMI", Q)


For Each mo As ManagementObject In mos.Get


Return Convert.ToInt32(mo.GetPropertyValue("CurrentTemperature") - 2732) / 10


Next


End Function


End Class






================================================================


<< VB6 >>

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
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|Archiver|手機版|InPowerS.Net

GMT+8, 2018-8-19 23:59

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表