完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
Imports System.Management Public Class GetIDClass Private Function GetHardDriveID() As String '获取硬盘ID Try GetHardDriveID = "" Dim info As ManagementBaseObject Dim query As New SelectQuery("Win32_DiskDrive") Dim search As New ManagementObjectSearcher(query) For Each info In search.Get() If info("Model") IsNot Nothing Then Return info("Model").ToString Else Return "" End If Next Catch ex As Exception Return "" End Try End Function Private Function GetMainBoardID() As String '获取主板ID Try GetMainBoardID = "" Dim info As ManagementBaseObject Dim query As New SelectQuery("Win32_BaseBoard") Dim search As New ManagementObjectSearcher("Select * FROM Win32_BaseBoard") For Each info In search.Get If info("Product") IsNot Nothing Then Return info("Product").ToString Else Return "" End If Next Catch ex As Exception Return "" End Try End Function Private Function GetCUPID() As String '获取CPUID Try GetCUPID = "" Dim info As ManagementBaseObject Dim query As New SelectQuery("Win32_Processor") Dim search As New ManagementObjectSearcher(query) For Each info In search.Get If info("ProcessorId") IsNot Nothing Then Return info("ProcessorId").ToString Else Return "" End If Next Catch ex As Exception Return "" End Try End Function End Class |
原文链接:VB.NET2005 取得磁盘、主板、CPU 的 ID,转载请注明来源!