GetVolumeInformation
BOOL GetVolumeInformation(
  LPCTSTR lpRootPathName,           // root directory
  LPTSTR lpVolumeNameBuffer,        // volume name buffer
  DWORD nVolumeNameSize,            // length of name buffer
  LPDWORD lpVolumeSerialNumber,     // volume serial number
  LPDWORD lpMaximumComponentLength, // maximum file name length
  LPDWORD lpFileSystemFlags,        // file system options
  LPTSTR lpFileSystemNameBuffer,    // file system name buffer
  DWORD nFileSystemNameSize         // length of file system name buffer
);

解决方案 »

  1.   

    '**************************************
    ' Name: Get Serialnumber from a harddisk
    '     
    ' Description:Get the Serialnumber from 
    '     your harddisk, cd rom or your disks.
    ' By: Manuel W.
    '
    ' Assumes:Make a label named label1 and 
    '     an commandbutton named command1.
    '
    'This code is copyrighted and has' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.7364/lngWId.1/qx/vb/scripts/ShowCode.
    '     htm'for details.'**************************************Option Explicit
    Private Declare Function GetVolumeInformation& Lib "kernel32" _
        Alias "GetVolumeInformationA" (ByVal lpRootPathName _
        As String, ByVal pVolumeNameBuffer As String, ByVal _
        nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
        lpMaximumComponentLength As Long, lpFileSystemFlags As _
        Long, ByVal lpFileSystemNameBuffer As String, ByVal _
        nFileSystemNameSize As Long)
        Const MAX_FILENAME_LEN = 256
    Private Sub Command1_Click()
        Label1.Caption = SerNum("C") 'C is the standard harddisk
    End Sub
    Public Function SerNum(Drive$) As Long
        Dim No&, s As String * MAX_FILENAME_LEN
        Call GetVolumeInformation(Drive + ":\", s, MAX_FILENAME_LEN, _
        No, 0&, 0&, s, MAX_FILENAME_LEN)
        SerNum = No
    End Function
    Private Sub Form_Load()
    End Sub
      

  2.   

    用GetVolumeInformation函数楼上已给出详细代码
      

  3.   

    给你个完整的程序
    在一个模块中声明如下函数:
    Public 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
    在窗体中加入如下代码:
    '窗体中包含两个按钮和一个驱动器列表框!
    Dim lserior As Long
    Dim p As String
    Private Function getSeriorNumber(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))
    getSeriorNumber = lSerialNum
    '在 strLabel 中为 磁盘卷标
    '在 strType 中为 文件系统类型
    End FunctionPrivate Sub Command1_Click()
    p = String(1, Drive1.Drive) & ":\"
    Label1.Caption = String(1, Drive1.Drive) & "盘的序列号为" & getSeriorNumber(p)
    End SubPrivate Sub Command2_Click()
    Unload Me
    End
    End SubPrivate Sub Drive1_Change()
    p = Drive1.Drive
    End Sub运行程序,即可测试各个驱动器的序列号!
      

  4.   

    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()
       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