通过WMI获得硬盘Id和CPU的物理序列号网卡的Mac地址

    技术2024-07-29  66

    获得硬盘序列号Mac Private Function GetMac() As String '获取第一个mac的id Dim MC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration") Dim MOC As ManagementObjectCollection MOC = MC.GetInstances() Dim Mac As String For Each WmiObj As ManagementObject In MOC If WmiObj("IPEnabled") Then If Mac <> "" Then Mac = Mac + " @ " End If Mac = Mac + CStr(WmiObj("MACAddress")) Exit For End If Next If Mac = "" Then Mac = "error" End If Return Mac End Function

     

     

    获得硬盘序列号Dim cmicWmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")Dim Uint32 As UInt32For Each cmicWmiObj As ManagementObject In cmicWmi.GetUint32 = cmicWmiObj("signature")NextTextBox1.Text = Uint32.ToString'获得CPU序列号Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Processor")Dim Uint32 As StringFor Each WmiObj As ManagementObject In Wmi.GetUint32 = WmiObj("ProcessorId")NextTextBox1.Text = Uint32'获得硬盘总容量Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")Dim Uint64 As UInt64For Each WmiObj As ManagementObject In Wmi.GetUint64 = WmiObj("size")NextTextBox1.Text = Uint64.ToString首先,引用System.Management;然后在代码中Imports System.Management;

    最新回复(0)