Private 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 Serial As Long, Vname As String, FSName As String 'Create buffers Vname = String$(255, Chr$(0)) FSName = String$(255, Chr$(0)) 'Get the volume information GetVolumeInformation "C:\", Vname, 255, Serial, 0, 0, FSName, 255 'Strip the extra chr$(0)'s Vname = Left$(Vname, InStr(1, Vname, Chr$(0)) - 1) FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1) MsgBox "The Volume name of C:\ is '" + Vname + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title End Sub
我遇到过磁盘序列号为“0”的硬盘,这是什么原因?在MS-DOS下键如DIR可看到:Volume Serial Number is 0000-0000 这对加密可是个意外的打击!!!!
丁凯的一篇文章《在WIN9X下怎样获得硬盘序列号》有详细介绍
"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 Serial As Long, Vname As String, FSName As String
'Create buffers
Vname = String$(255, Chr$(0))
FSName = String$(255, Chr$(0))
'Get the volume information
GetVolumeInformation "C:\", Vname, 255, Serial, 0, 0, FSName, 255
'Strip the extra chr$(0)'s
Vname = Left$(Vname, InStr(1, Vname, Chr$(0)) - 1)
FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
MsgBox "The Volume name of C:\ is '" + Vname + "', the File system name
of C:\ is '" + FSName + "' and the serial number of C:\ is '" +
Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
End Sub