Const BIGNUM = 1000000
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 LongPrivate Function HDNum() As Long
 '硬盘序列号
    Dim nRet As Long
    Dim VolName As String
    Dim VolSN As Long
    Dim MaxCompLen As Long
    Dim VolFlags As Long
    Dim VolFileSys As String
    Dim xlh As String
    VolName = Space$(256)
    VolFileSys = Space$(256)
    nRet = GetVolumeInformation("C:\", VolName, Len(VolName), VolSN, MaxCompLen, VolFlags, VolFileSys, Len(VolFileSys))
    HDNum = VolSN
End Function

解决方案 »

  1.   

    咋会哦
    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 Const MAX_FILENAME_LEN = 256
    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 Long    Call GetVolumeInformation(sDrv & ":\", str, MAX_FILENAME_LEN, RetVal, a, b, str2, MAX_FILENAME_LEN)
        DriveSerial = RetVal
    End Function
      

  2.   

    to coolsky(天心)
    这个函数获得的是分区序列号,是可以随便更改的,最好能给出厂家固定的出厂序列号,那才是不可更改的。
      

  3.   

    我有读取硬盘序号的类但不是以上读取什么cde盘的哪种而是真正的序号一个硬盘一个要的话给我来信。[email protected]
      

  4.   

    #include <stdafx.h>
    #include <windows.h> 
    #include <iostream.h> 
    #include <stdio.h> #define DFP_GET_VERSION 0x00074080 
    #define DFP_SEND_DRIVE_COMMAND 0x0007c084 
    #define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1) 
    typedef struct _GETVERSIONOUTPARAMS { 
      BYTE bVersion;  // Binary driver version. 
      BYTE bRevision;  // Binary driver revision. 
      BYTE bReserved;  // Not used. 
      BYTE bIDEDeviceMap; // Bit map of IDE devices. 
      DWORD fCapabilities; // Bit mask of driver capabilities. 
      DWORD dwReserved[4]; // For future use. 
    } GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS { 
      BYTE bFeaturesReg;  // Used for specifying SMART "commands". 
      BYTE bSectorCountReg; // IDE sector count register 
      BYTE bSectorNumberReg; // IDE sector number register 
      BYTE bCylLowReg;   // IDE low order cylinder value 
      BYTE bCylHighReg;  // IDE high order cylinder value 
      BYTE bDriveHeadReg;  // IDE drive/head register 
      BYTE bCommandReg;  // Actual IDE command. 
      BYTE bReserved;   // reserved for future use.  Must be zero. 
    } IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS { 
      DWORD cBufferSize;  // Buffer size in bytes 
      IDEREGS irDriveRegs;  // Structure with drive register values. 
      BYTE bDriveNumber;  // Physical drive number to send 
      // command to (0,1,2,3). 
      BYTE bReserved[3];  // Reserved for future expansion. 
      DWORD dwReserved[4];  // For future use. 
      //BYTE  bBuffer[1];   // Input buffer. 
    } SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS { 
      BYTE bDriverError;  // Error code from driver, 
      // or 0 if no error. 
      BYTE bIDEStatus;   // Contents of IDE Error register. 
      // Only valid when bDriverError 
     // is SMART_IDE_ERROR. 
      BYTE bReserved[2];  // Reserved for future expansion. 
      DWORD dwReserved[2];  // Reserved for future expansion. 
    } DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS { 
      DWORD    cBufferSize;  // Size of bBuffer in bytes 
      DRIVERSTATUS DriverStatus;  // Driver status structure. 
      BYTE   bBuffer[512];   // Buffer of arbitrary length 
      // in which to store the data read from the drive. 
    } SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR { 
      USHORT wGenConfig; 
      USHORT wNumCyls; 
      USHORT wReserved; 
      USHORT wNumHeads; 
      USHORT wBytesPerTrack; 
      USHORT wBytesPerSector; 
      USHORT wSectorsPerTrack; 
      USHORT wVendorUnique[3]; 
      CHAR sSerialNumber[20]; 
      USHORT wBufferType; 
      USHORT wBufferSize; 
      USHORT wECCSize; 
      CHAR sFirmwareRev[8]; 
      CHAR sModelNumber[40]; 
      USHORT wMoreVendorUnique; 
      USHORT wDoubleWordIO; 
      USHORT wCapabilities; 
      USHORT wReserved1; 
      USHORT wPIOTiming; 
      USHORT wDMATiming; 
      USHORT wBS; 
      USHORT wNumCurrentCyls; 
      USHORT wNumCurrentHeads; 
      USHORT wNumCurrentSectorsPerTrack; 
      ULONG ulCurrentSectorCapacity; 
      USHORT wMultSectorStuff; 
      ULONG ulTotalAddressableSectors; 
      USHORT wSingleWordDMA; 
      USHORT wMultiWordDMA; 
      BYTE bReserved[128]; 
    } IDSECTOR, *PIDSECTOR;
      

  5.   

    http://www.csdn.net/expert/topic/934/934383.xml?temp=7.789248E-02
      

  6.   

    http://www.dapha.net/vb/list.asp?id=1886
      

  7.   

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

  8.   

    http://www.csdn.net/expert/topic/934/934383.xml?temp=.7288172http://www.dapha.net/vb/list.asp?id=1886