Public 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)Public Function DriveSerial(ByVal sDrv As String) As Long
Dim RetVal As Long
Dim str As String * MAX_FILENAME_LEN
Dim str2 As String * MAX_FILENAME_LEN
Dim a As Long
Dim b As LongCall GetVolumeInformation(sDrv & ":\", str, MAX_FILENAME_LEN, RetVal, a, b, str2, MAX_FILENAME_LEN)
    DriveSerial = RetVal
End Function调用方法
b=DriveSerial("C")

解决方案 »

  1.   

    物理序列号(不会因格式化而改变)
    http://www.csdn.net/expert/topic/934/934383.xml?temp=.7288172http://www.dapha.net/vb/list.asp?id=1886
      

  2.   

    斑竹用VC编写的DLL,可以获得硬盘的型号、序列号以及计算机 ID,带Delphi的源程序,在Win2K下通过,但是没有在Win9X下试过,感兴趣的朋友可以在Win9X 下试一下,或者编写一个VB的范例。
    函数以及定义:
    function ReadPhysicalDrive(driveID:integer;buffer:Pointer;bufLen:integer):integer; stdcall; external 'DiskID.dll' name 'ReadPhysicalDriveInNT';
    获得WinNT下的硬盘型号以及序列号。参数driveID为硬盘的位置,IDE1上的主盘为0,类推到IDE2上的从盘的driveID为3。
    function ReadPhysicalDrive9X(driveID:integer;buffer:Pointer;bufLen:integer):integer; stdcall; external 'DiskID.dll' name 'ReadDrivePortsInWin9X'; 
    获得Win9X下的硬盘型号以及序列号。参数同上
    function getHardDriveComputerID:int64; stdcall; external 'DiskID.dll' name 'getHardDriveComputerID';
    获得计算机的ID http://www.applevb.com/lib/diskio.rar
    http://www.applevb.com/DiskID.rar
      

  3.   

    新建一个模文件,加入代码:
    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 LongGlobal GethdVal As Long在form1_load事件中加入
    Dim Str1 As String * 256
    Dim Str2 As String * 256
    Dim Lon1 As Long
    Dim Lon2 As Long
    Call GetVolumeInformation("C:\", Str1, 256, GetVal, Lon1, Lon2, Str2, 256)Text1.Text = GethdVal