用API 函数GetVolumeInformation得到的不是硬盘的序列号!!!
十多年来,创新互联公司不忘初心,以网站建设互联网行业服务标杆为目标,不断提升技术设计服务水平,帮助客户在互联网推广自己的产品、服务和品牌,为客户创造价值从而实现自身价值!
BOOL GetVolumeInformation(
LPCTSTR lpRootPathName,
LPTSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize,
LPDWORD lpVolumeSerialNumber,
LPDWORD lpMaximumComponentLength,
LPDWORD lpFileSystemFlags,
LPTSTR lpFileSystemNameBuffer,
DWORD nFileSystemNameSize
);
看看英文啊:VolumeSerialNumber!得到的只是卷区序列号!
硬盘的序列号应该是
Drive Model Number________________: WDC WD400EB-00CPF0
Drive Serial Number_______________: WD-WCAATF083586
Drive Controller Revision Number__: 06.04G06
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 40020664320 bytes
中:
Drive Serial Number_______________: WD-WCAATF083586 这才是硬盘Serial Number!!!!
这个号是不会因为你格式化硬盘而改动,也不是网上流传的修改工具能改的,(其实网上流传的修改工具的也不过是卷区号而已!)
建议用 DiskID.dll或DiskID32.dll来获取
用diskid.dll和disk32.dll获得硬盘序列号
1.调用diskid.dll实现:
Option Explicit
Private Declare Function IsWinNT Lib "DiskID.DLL" () As Long
Private Declare Function ReadPhysicalDrive9X Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Declare Function ReadPhysicalDriveInNT Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Type DRIVER_INFO_OK
ModalNumber(39) As Byte
SerialNumber(19) As Byte
ControlNum(7) As Byte
DriveType As Long
Cylinders As Long
Heads As Long
Sectors As Long
End Type
Private Sub Command1_Click()
Dim x As DRIVER_INFO_OK
Dim i As Long
If IsWinNT = 1 Then
i = ReadPhysicalDriveInNT(ByVal 0, ByVal VarPtr(x), ByVal 256)
Else
i = ReadPhysicalDrive9X(ByVal 0, ByVal VarPtr(x), ByVal 256)
End If
Dim s As String
s = StrConv(x.ModalNumber, vbUnicode)
s = Left(s, InStr(1, s, Chr(0)) - 1)
MsgBox "硬件厂商代码为:" + s
s = StrConv(x.SerialNumber, vbUnicode)
s = Left(s, InStr(1, s, Chr(0)) - 1)
MsgBox "硬盘序列号为:" + s
End Sub
2.调用diskid32.dll实现:
Option Explicit
Private Declare Function DiskID32 Lib "DiskID32.DLL" (ByRef DiskModel As Byte, ByRef DiskID As Byte) As Long
Private Sub Command1_Click()
Dim DiskModel(31) As Byte, DiskID(31) As Byte, i As Integer, Model As String, ID As String
If DiskID32(DiskModel(0), DiskID(0)) 1 Then
MsgBox "get diskid32 err"
Exit Sub
End If
For i = 0 To 31
If Chr(DiskModel(i)) Chr(0) Then
Model = Model Chr(DiskModel(i))
End If
If Chr(DiskID(i)) Chr(0) Then
ID = ID Chr(DiskID(i))
End If
Next
MsgBox "硬件产生代码为:" + Model
MsgBox "硬盘序列号为:" + ID
End Sub
说明:diskid.dll可从下载
diskid32.dll可从下载
猜想你使用时是用类名.方法名?
改成(new 类名()).方法名试试。
窗体上不存在 Text1 这个控件,所以出错。
通常文本框控件在VB6中默认是Text1,而在VB.NET中则是TextBox1,是不是这个错误?如果是,那么你可以把代码中的全部Text1改为TextBox1,或者把文本框控件的名称改为Text1也行。