获取HDD序列号时出现“方法或操作未实现”的错误

时间:2016-12-19 08:01:18

标签: vb.net

我正在尝试使用以下代码获取硬盘序列号...

Imports System.IO
Imports System.Management



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        HDDCheck()
    End Sub

    Private Sub HDDCheck()
            Try
                Dim HDD_Serial As String
                 Dim hdd As New ManagementObjectSearcher("select * from Win32_DiskDrive")
                For Each hd In hdd.Get
                    HDD_Serial = hd("SerialNumber")
                    If Not "20202020202020200332043354132314a5341" = HDD_Serial Then
                       Me.Close()
                    Else
                        Exit For
                    End If
                Next

            Catch ex As Exception

            End Try
        End Sub

但我收到了以下错误...

  

捕获了System.NotImplementedException Message =方法或   操作未实施。

相同的代码在我之前的应用程序上运行在同一台机器上, 但这是我写的新应用程序,这给了我一个错误...

我缺少什么?

1 个答案:

答案 0 :(得分:0)

我只需更改代码

来自

Dim hdd As New ManagementObjectSearcher("select * from Win32_DiskDrive")

Dim hdd As New Management.ManagementObjectSearcher("select * from Win32_DiskDrive")

感谢David Wilson