Option Explicit
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
Const FILE_VOLUME_IS_COMPRESSED = &H8000
Function GetSerialNumber(strDrive As String) As Long
Dim SerialNum As Long
Dim Res As Long
Dim Temp1 As String
Dim Temp2 As String
Temp1 = String$(255, Chr$(0))
Temp2 = String$(255, Chr$(0))
Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
MsgBox Temp1
MsgBox Temp2
MsgBox Hex(SerialNum)
GetSerialNumber = SerialNum
End Function
Public Sub GetVolInfo(ByVal path As String)
Dim aa As Long
Dim VolName As String
Dim fsysName As String
Dim VolSeri As Long, compress As Long
Dim Sysflag As Long, Maxlen As Long
'初试化字符串的长度
VolName = String(255, 0)
fsysName = String(255, 0)
aa = GetVolumeInformation(path, VolName, 256, VolSeri, Maxlen, _
Sysflag, fsysName, 256)
VolName = Left(VolName, InStr(1, VolName, Chr(0)) - 1)
fsysName = Left(fsysName, InStr(1, fsysName, Chr(0)) - 1)
compress = Sysflag And FILE_VOLUME_IS_COMPRESSED
If compress = 0 Then
MsgBox "未压缩驱动器"
Else
MsgBox "压缩驱动器"
End If
MsgBox "驱动器卷标 :" + VolName
MsgBox "驱动器标号 : " + Hex(VolSeri)
MsgBox "驱动器文件系统 (FAT, HPFS, or NTFS)" + fsysName
MsgBox "支持的文件名长度" + Str$(Maxlen)
End Sub
Private Sub Command1_Click()
MsgBox GetSerialNumber("C:\")
End Sub
Private Sub Command2_Click()
Call GetVolInfo("C:\")
End Sub
Private Sub Command3_Click()
Dim cr As String
Dim Twidth As Integer
Dim Theight As Integer
cr = Chr$(13) + Chr$(10)
Twidth% = Screen.Width \ Screen.TwipsPerPixelX
Theight% = Screen.Height \ Screen.TwipsPerPixelY
MsgBox "屏幕大小为" + cr + cr + Str$(Twidth%) + " x" + Str$(Theight%), 64, "Info"
End Sub