'add a reference to System.Management.dll
Imports System.Management
Public Class GetIDClass
Public Function GetID() As String
Dim ID As String
ID = GetHardDriveID()
If ID <> "" Then
Return ID
Else
ID = GetMainBoardID()
If ID <> "" Then
Return ID
Else
ID = GetCUPID()
If ID <> "" Then
Return ID
Else
Return "Err"
End If
End If
End If
End Function
Private Function GetHardDriveID() As String
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
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
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ID As String
ID = GetHardDriveID()
MsgBox("硬盘:" & ID)
ID = GetMainBoardID()
MsgBox("主板:" & ID)
ID = GetCUPID()
MsgBox("CPU:" & ID)
End Sub
End Class
Imports System.Management
Public Class GetIDClass
Public Function GetID() As String
Dim ID As String
ID = GetHardDriveID()
If ID <> "" Then
Return ID
Else
ID = GetMainBoardID()
If ID <> "" Then
Return ID
Else
ID = GetCUPID()
If ID <> "" Then
Return ID
Else
Return "Err"
End If
End If
End If
End Function
Private Function GetHardDriveID() As String
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
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
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ID As String
ID = GetHardDriveID()
MsgBox("硬盘:" & ID)
ID = GetMainBoardID()
MsgBox("主板:" & ID)
ID = GetCUPID()
MsgBox("CPU:" & ID)
End Sub
End Class
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |