top
Loading...
取得磁盤序列號、卷標和文件系統類型
磁盤序列號在每次軟盤或硬盤格式化后都重新生成,并且不回重復。許多程序員用此加密。其實也可以修改該函數,可以得到磁盤卷標和文件系統類型信息。

聲明:

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))
  ' 文件系統類型 一般為 FAT
    R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType))
    GetSerialNumber = lSerialNum
  '在 strLabel 中為 磁盤卷標
  '在 strType  中為 文件系統類型
End Function


用法:

當驅動器不存在時,函數返回 0。如果是個非根目錄,也將返回 0:

lSerial = GetSerialNumber("c:")
作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗