请问如何用VB读取硬盘序号!?!?!

解决方案 »

  1.   

    去http://www.21tx.com/src/vb/看看,很详细
      

  2.   

    '模块
    Option ExplicitPublic 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'窗体
    '拖一个drive控件,一个button控件
    Option ExplicitPrivate Sub Command1_Click()
        MsgBox Hex(DriveSerial(Left(Drive1.Drive, 1)))
    End Sub
      

  3.   

    '读取硬盘硬件参数
    Public Function GetHDINFO(Optional DriverNum As Integer = 0) As TypeIDSECTOR
      Dim SecAtt As SECURITY_ATTRIBUTES
      Dim Ovlp As OVERLAPPED
      Dim vers As TypeGETVERSIONOUTPARAMS
      Dim cIn As TypeSENDCMDINPARAMS
      Dim cOut As TypeSENDCMDOUTPARAMS
      Dim phdinfo As TypeIDSECTOR
      Dim h As Long
      Dim i As Long
      
      h = CreateFile("\\.\Smartvsd", 0, 0, SecAtt, CREATE_NEW, 0, 0)
      If h = 0 Then
        GetHDINFO = phdinfo
        Exit Function
      End If
      If DeviceIoControl(h, DFP_GET_VERSION, 0, 0, vers, Len(vers), i, Ovlp) = 0 Then
        GoTo Exit_Sub
      End If
      If (vers.fCapabilities And 1) = 0 Then
        GoTo Exit_Sub
      End If
      If (DriverNum And 1) <> 0 Then
        cIn.irDriveRegs.bDriveHeadReg = &HB0
      Else
        cIn.irDriveRegs.bDriveHeadReg = &HA0
      End If
      If (vers.fCapabilities And (16 / (2 ^ DriverNum))) <> 0 Then
        GoTo Exit_Sub
      Else
        cIn.irDriveRegs.bCommandReg = &HEC
      End If
      cIn.bDriveNumber = DriverNum
      cIn.irDriveRegs.bSectorCountReg = 1
      cIn.irDriveRegs.bSectorNumberReg = 1
      cIn.cBufferSize = 512
      If DeviceIoControl(h, DFP_RECEIVE_DRIVE_DATA, cIn, Len(cIn), cOut, Len(cOut), i, Ovlp) = 0 Then
            GoTo Exit_Sub
      End If
      '参数传递
      '注:只传递了 产品名称,型号编码,序列号 三个参数
      phdinfo.sModelNumber = BytesToStr(cOut.bBuffer, 40, 53)
      phdinfo.sFirmwareRev = BytesToStr(cOut.bBuffer, 8, 45)
      phdinfo.sSerialNumber = BytesToStr(cOut.bBuffer, 20, 19)
    Exit_Sub:
      CloseHandle h
      GetHDINFO = phdinfo
    End Function
      

  4.   

    谁能发一个源文件给我呀!![email protected] 哟先谢了哟,