如何获取硬盘卷标、序列号和文件系统类型?
 
     磁盘序列号在每次软盘或硬盘格式化后都重新生成,并且不回重复。许多程序员用此加密。其实也可以修改该函数,可以得到磁盘卷标和文件系统类型信息。声明:
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 strLabel As String, strType 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:\")
 
   
 
  
 

解决方案 »

  1.   

    如何取得磁盘序列号?
     
    调用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试试吧!
      

  2.   

    如何取得磁盘序列号?调用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
      

  3.   

    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
      

  4.   

    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
      

  5.   

    www.21code.com
    www.vbeden.com
    自己找吧
      

  6.   

    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 strLabel As String, strType 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("A:\")
     
       
     
      
      

  7.   

    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
    http://www.csdn.net/expert/topic/577/577681.xml?temp=.5721704
      

  8.   

    LonSoft Hard-Disk Serial ActiveX 控件1.01 For VB5/VB6
    Copyright (c) 2002 Lonsoft Studio.
    All Rights Reserved作者:  [email protected] 
    注册: [email protected] (注册时使用)
    Web:http://www.dapha.net/lonsoft/index.htm
    Oicq:  8892098(请留言)
                     --控件介绍 -----------------------LonSoft Hard-Disk Serial ActiveX是一个32位ActiveX控件,
    用于获取你的计算机硬盘的相关信息,包括序列号、型号、修订号、
    磁盘缓存大小、磁头数、柱面数、每磁道的扇区数等。
    如果你是共享软件的作者,你可以利用这些信息做什么呢?---控件使用-----------------
    属性:1.Controller:取得硬盘控制器
    返回值: 0=Primary Controller   1=Secondary Controller 
            2=Tertiary Controller  3=Quaternary Controller 2.ControllerType:取得硬盘控制器是在主盘还是在副盘
    返回值: 0=主盘   1=副盘3.DriveType:驱动器类型
    返回值:"Removable"; "Fixed"; "Unknow";4.SerialNumber:硬盘序列号
    返回值:返回硬盘序列号的字符串。5.ModelNumber:硬盘型号
    返回值:返回硬盘型号的字符串。如"QUANTUM FIREBALLP LM10.2"6.RevisionNumber:硬盘修订号
    返回值:返回硬盘修订号,字符串。7.RevisionNumber:硬盘缓存的大小
    返回值:返回硬盘缓存的大小,字符串。8.Heads:硬盘的磁头数
    返回值:返回硬盘的磁头数,字符串。9.Cylinders:硬盘的柱面数
    返回值:返回硬盘的柱面数,字符串。10.Sectors:硬盘的每磁道的扇区数
    返回值:返回硬盘每磁道的扇区数,字符串。11.ComputerID:与用户计算机相关的序列号
    返回值:返回与用户计算机相关的序列号,字符串。如196727438等...方法:语法: ReadDiskSerial (<RegName>,<RegCode>) 
    功能:读取硬盘的资料。
    参数:regName为注册名,regCode为注册序列号
    返回值:Ture 注册名及注册序号有效;否则弹出一对话框。