WMI判断电池电量、笔记本、台式机
Imports System.Management Public Class Form1 '获得电池剩余电量 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mc As New ManagementClass("Win32_Battery") For Each obj As ManagementObject In mc.GetInstances() TextBox1.Text = obj("EstimatedChargeRemaining").ToString Next End Sub '获得计算机类型,Desptop(3),Notebook(10) Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim mc As New ManagementClass("Win32_SystemEnclosure") For Each obj As ManagementObject In mc.GetInstances() For Each i As UShort In obj("ChassisTypes") TextBox1.Text = CInt(i) Next Next End Sub End Class
'获得主板序列号 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim mc As New ManagementClass("Win32_BIOS") For Each obj As ManagementObject In mc.GetInstances() TextBox1.Text = (obj("SerialNumber").ToString.Replace(" ", "").ToUpper & "TOREDSAPTOOL").Substring(0, 12) Next End Sub
部分取不到主板序列号,是什么原因?