用这个API:GetVolumeInformation,具体自己找找MSDN吧。

解决方案 »

  1.   

    GetVolumeInformation VB声明 
    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 
    说明 
    获取与一个磁盘卷有关的信息 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    lpRootPathName String,欲获取信息的那个卷的根路径 
    lpVolumeNameBuffer String,用于装载卷名(卷标)的一个字串 
    nVolumeNameSize Long,lpVolumeNameBuffer字串的长度 
    lpVolumeSerialNumber Long,用于装载磁盘卷序列号的变量 
    lpMaximumComponentLength Long,指定一个变量,用于装载文件名每一部分的长度。例如,在“c:\component1\component2.ext”的情况下,它就代表component1或component2名称的长度 
    lpFileSystemFlags Long,用于装载一个或多个二进制位标志的变量。对这些标志位的解释如下: 
    FS_CASE_IS_PRESERVED 文件名的大小写记录于文件系统 
    FS_CASE_SENSITIVE 文件名要区分大小写 
    FS_UNICODE_STORED_ON_DISK 文件名保存为Unicode格式 
    FS_PERSISTANT_ACLS 文件系统支持文件的访问控制列表(ACL)安全机制 
    FS_FILE_COMPRESSION 文件系统支持逐文件的进行文件压缩 
    FS_VOL_IS_COMPRESSED 整个磁盘卷都是压缩的 
    lpFileSystemNameBuffer String,指定一个缓冲区,用于装载文件系统的名称(如FAT,NTFS以及其他) 
    nFileSystemNameSize Long,lpFileSystemNameBuffer字串的长度 
      

  2.   

    call getvolumeinformation( "c:\",tempstr1,256,getval,templon1,templon2,tempstr2,256)
    text1.text=getval
      

  3.   

    Option ExplicitPrivate 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 LongPrivate Sub Command1_Click()
    Dim root As String
    Dim volume_name As String
    Dim serial_number As Long
    Dim max_component_length As Long
    Dim file_system_flags As Long
    Dim file_system_name As String
    Dim pos As Integer    root = Text1.Text
        volume_name = Space$(1024)
        file_system_name = Space$(1024)    If GetVolumeInformation(root, volume_name, _
            Len(volume_name), serial_number, _
            max_component_length, file_system_flags, _
            file_system_name, Len(file_system_name)) = 0 _
        Then
            MsgBox "Error getting volume information."
            Exit Sub
        End If    pos = InStr(volume_name, Chr$(0))
        volume_name = Left$(volume_name, pos - 1)
        lblVolumeName.Caption = volume_name    lblSerialNumber.Caption = Format$(serial_number)    lblMaxComponentLength.Caption = Format$(max_component_length)    pos = InStr(file_system_name, Chr$(0))
        file_system_name = Left$(file_system_name, pos - 1)
        lblFileSystem.Caption = file_system_name    lblFlags.Caption = "&&H" & Hex$(file_system_flags)
    End Sub
      

  4.   

    http://ygyuan.go.163.com/
    http://ygyuan.3322.net/
    下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s  As String
    s = String(1024, Chr(0))
    GetDiskSN (s)
    s = Trim(Replace(s, Chr(0), ""))
    msgbox s 
      

  5.   

    这个程序一定是对的;须注意的是如果返回的是逻辑驱动器则是Volume 'even this will bring up same result:
    'you will get two different serail number for the two drives.
    'It seems as if logical drives get their own serial number...
    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()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    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
      

  6.   

    磁盘序列号用来加密,每次格式化后生成,而且绝不重复.在vb中我是这样获取它的:
      在窗体上放一个label放一个command
      然后粘上这一段代码,就可以获得d:盘的序列号:
      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))
              R  =  GetVolumeInformation(sRoot,  strLabel,  Len(strLabel),  lSerialNum,  0,  0,  strType,  Len(strType))
              GetSerialNumber  =  lSerialNum
      End  Function
      
      Private  Sub  Command1_Click()
              i  =  GetSerialNumber("d:\")
              Label1.Caption  =  "序列号为"  +  CStr(i)
      End  Sub