如何使用VB.NET读取硬盘卷序列号,但没有Visual Studio或任何外部库的任何第三方插件 - 如果可能,我需要本机VB.NET代码。
答案 0 :(得分: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
答案 1 :(得分:0)
不确定这是否是您正在寻找的,但快速谷歌搜索引导我访问此网站:
答案 2 :(得分: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