调用API函数 GetVolumeInformation。API声明:Declare Function GetVolumeInformation Lib "kernel32" _ Alias "GetVolumeInformationA" _ (ByVal lpRootPathName As String, _ ByVal lpVolumeNameBuffer As String, _ ByVal nVolumeNameSize As Long, _ lpVolumeSerialNumber As Long, _ lpMaximumComponentLength As Long, _ lpFileSystemFlags As Long, _ ByVal lpFileSystemNameBuffer As String, _ ByVal nFileSystemNameSize As Long) As Long程序:Private Sub Form_Load() Dim sDriveLetter As String Dim RetVal As Long Dim lpName As String Dim nSize As Long Dim nSerial As Long Dim lpMaxComp As Long Dim nFileFlags As Long Dim lpFileName As String lpName = Space(255) lpFileName = Space(255) nSize = 255 sDriveLetter = "a:\" ’这里你可以指定任何盘号 RetVal = GetVolumeInformation(sDriveLetter, lpName, _ nSize, nSerial, lpMaxComp, nFileFlags, lpFileName, nSize) '你可以看出,不仅能得到序列号,还可以得到其他很多信息 If RetVal = 0 Then '这里是你的错误处理代码 Exit Sub 'Quit the subroutine Else lblDriveSerial.Caption = CStr(nSerial) '假定你已经建立了这个标签,将在标签上显示序列号. End If End Sub
http://ygyuan.go.163.com/ http://ygyuan.3322.net/ 下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String s = String(1024, Chr(0)) GetDiskSN (s) s = Trim(Replace(s, Chr(0), "")) msgbox s
磁盘序列号用来加密,每次格式化后生成,而且绝不重复.在vb中我是这样获取它的: 在窗体上放一个label放一个command 然后粘上这一段代码,就可以获得d:盘的序列号: Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Function GetSerialNumber(sRoot As String) As Long Dim lSerialNum As Long Dim R As Long Dim sTemp1 As String, sTemp2 As String strLabel = String$(255, Chr$(0)) strType = String$(255, Chr$(0)) R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType)) GetSerialNumber = lSerialNum End Function
Private Sub Command1_Click() i = GetSerialNumber("d:\") Label1.Caption = "序列号为" + CStr(i) End Sub
Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long程序:Private Sub Form_Load()
Dim sDriveLetter As String
Dim RetVal As Long
Dim lpName As String
Dim nSize As Long
Dim nSerial As Long
Dim lpMaxComp As Long
Dim nFileFlags As Long
Dim lpFileName As String
lpName = Space(255)
lpFileName = Space(255)
nSize = 255 sDriveLetter = "a:\" ’这里你可以指定任何盘号 RetVal = GetVolumeInformation(sDriveLetter, lpName, _
nSize, nSerial, lpMaxComp, nFileFlags, lpFileName, nSize)
'你可以看出,不仅能得到序列号,还可以得到其他很多信息 If RetVal = 0 Then
'这里是你的错误处理代码
Exit Sub 'Quit the subroutine
Else
lblDriveSerial.Caption = CStr(nSerial)
'假定你已经建立了这个标签,将在标签上显示序列号.
End If
End Sub
我可没试过
http://ygyuan.3322.net/
下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String
s = String(1024, Chr(0))
GetDiskSN (s)
s = Trim(Replace(s, Chr(0), ""))
msgbox s
在窗体上放一个label放一个command
然后粘上这一段代码,就可以获得d:盘的序列号:
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Function GetSerialNumber(sRoot As String) As Long
Dim lSerialNum As Long
Dim R As Long
Dim sTemp1 As String, sTemp2 As String
strLabel = String$(255, Chr$(0))
strType = String$(255, Chr$(0))
R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType))
GetSerialNumber = lSerialNum
End Function
Private Sub Command1_Click()
i = GetSerialNumber("d:\")
Label1.Caption = "序列号为" + CStr(i)
End Sub