分享

VB.NET2005 取得磁盘、主板、CPU 的 ID

 江南兰亭馆 2014-06-10

VB.NET2005 取得磁盘、主板、CPU 的 ID

 (2011-07-28 12:46:01)
标签: 

转载

VB.NET2005 取得磁盘、主板、CPU 的 ID
Imports System.Management
Public Class GetIDClass
    Public Sub New()
    End Sub
    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
            Ne

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约