如何使用 VB.NET 读取 HDD 卷序列号,但没有 Visual Studio 的任何第三方插件或任何外部库 - 如果可能,我需要本机 VB.NET 代码。
Robert Jung
问问题
12605 次
3 回答
2
Public Function GetDriveSerialNumber() As String
Dim DriveSerial As Long
Dim fso As Object, Drv As Object
'Create a FileSystemObject object
fso = CreateObject("Scripting.FileSystemObject")
Drv = fso.GetDrive(fso.GetDriveName(AppDomain.CurrentDomain.BaseDirectory))
With Drv
If .IsReady Then
DriveSerial = .SerialNumber
Else '"Drive Not Ready!"
DriveSerial = -1
End If
End With
'Clean up
Drv = Nothing
fso = Nothing
GetDriveSerialNumber = Hex(DriveSerial)
End Function
于 2013-08-06T18:07:22.097 回答
0
不确定这是否是您要查找的内容,但快速谷歌搜索将我带到该网站:
于 2012-08-24T00:48:36.977 回答
0
' Function driveser (model)
' Returns the serial number of the drive specified in "model" or an empty string.
' Please include this is you are going to use it.
' (C) By Zibri 2013
' Free for non commercial use.
' zibri AT zibri DOT org
Function driveser(ByVal model As String) As String
Dim devid As String = ""
driveser = ""
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_DiskDrive WHERE Model LIKE '%" + model + "%'")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("SerialNumber") <> "" Then driveser = queryObj("SerialNumber")
Debug.Print(queryObj("Model") + ":" + driveser)
Next
Catch err As ManagementException
Debug.Print("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
于 2013-03-01T01:07:40.880 回答