您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 开发专栏 > VB开发 > 正文
·速成电脑精英(包分配)白领高薪一族从这里开始



-Java套接字编程(下)
-MediaStudio Pro 6.5教程
-三款卸载软件最新试用
-基于Visual C++的Winsock API研究

取得磁盘序列号、卷标和文件系统类型
2001-11-08· · ··yesky

  磁盘序列号在每次软盘或硬盘格式化后都重新生成,并且不回重复。许多程序员用此加密。其实也可以修改该函数,可以得到磁盘卷标和文件系统类型信息。

  声明:

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:\")
■ 相关内容
 磁盘整理另类办法
 枚举出局域网上所有网络资源
 用API函数实现文件夹列表
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!