我已经能够取得并口硬盘的物理序列号了,但是用该代码不能取得串行硬盘的物理序列号,很是苦闷!特求助!

解决方案 »

  1.   

    '把以下代码加入模块中,直接调用GetSerial()即可得到相应序列号   
        
      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   
        
      Public   Function   GetSerial()   As   String   
      Dim   rel   As   Long   
        
      Dim   VolName   As   String             '磁盘名称   
      Dim   fsysName   As   String           '磁盘格式   
      Dim   VolSerial   As   Long             '磁盘序列号   
      Dim   Sysflag   As   Long   
      Dim   Maxlen   As   Long   
        
      VolName   =   String(256,   0)   
      fsysName   =   String(256,   0)   
        
      rel   =   GetVolumeInformation("c:\",   VolName,   256,   VolSerial,   Maxlen,   Sysflag,   fsysName,   256)   
        
        
      GetSerial   =   Hex(VolSerial)   
        
      End   Function   
      '补充:以上得到的是C盘的序列号,如果想得到D盘的把C:\   换成   D:\ 即可
      

  2.   


    Option Explicit
    '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Private Const MAX_IDE_DRIVES       As Long = 4
    Private Const IDENTIFY_BUFFER_SIZE       As Long = 512
    Private Const DFP_SEND_DRIVE_COMMAND       As Long = &H7C084
    Private Const DFP_RECEIVE_DRIVE_DATA       As Long = &H7C088
    Private Const CREATE_NEW = 1
    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2
    'Private Const INVALID_HANDLE_VALUE = ((Handle) - 1)
    Private Type GETVERSIONOUTPARAMS
            bVersion   As Byte                 '   Binary   driver   version.
            bRevision   As Byte               '   Binary   driver   revision.
            bReserved   As Byte               '   Not   used.
            bIDEDeviceMap   As Byte       '   Bit   map   of   IDE   devices.
            fCapabilities   As Long       '   Bit   mask   of   driver   capabilities.
            dwReserved(3)   As Long       '   For   future   use.
    End Type
    Private Type IDEREGS
            bFeaturesReg   As Byte                 '   Used   for   specifying   SMART   "commands".
            bSectorCountReg   As Byte           '   IDE   sector   count   register
            bSectorNumberReg   As Byte         '   IDE   sector   number   register
            bCylLowReg   As Byte                     '   IDE   low   order   cylinder   value
            bCylHighReg   As Byte                   '   IDE   high   order   cylinder   value
            bDriveHeadReg   As Byte               '   IDE   drive/head   register
            bCommandReg   As Byte                   '   Actual   IDE   command.
    End TypePrivate Type SENDCMDINPARAMS
            cBufferSize   As Long                   '   Buffer   size   in   bytes
            irDriveRegs   As IDEREGS             '   Structure   with   drive   register   values.
            bDriveNumber   As Byte                 '   Physical   drive   number   to   send
            bReserved(2)   As Byte                 '   Reserved   for   future   expansion.
            dwReserved(3)   As Long               '   For   future   use.
            bBuffer(0)   As Byte                     '   Input   buffer.
    End Type
    Private Const IDE_ATAPI_ID       As Long = &HA1           '   Returns   ID   sector   for   ATAPI.
    Private Const IDE_ID_FUNCTION       As Long = &HEC           '   Returns   ID   sector   for   ATA.
    Private Const IDE_EXECUTE_SMART_FUNCTION       As Long = &HB0           '   Performs   SMART   cmd.
    Private Type DRIVERSTATUS
            bReserved(1)   As Byte                 '   Reserved   for   future   expansion.
            dwReserved(1)   As Long               '   Reserved   for   future   expansion.
    End TypePrivate Type SENDCMDOUTPARAMS
            cBufferSize   As Long                   '   Size   of   bBuffer   in   bytes
            drvStatus   As DRIVERSTATUS       '   Driver   status   structure.
            bBuffer(0)   As Byte                     '   Buffer   of   arbitrary   length   in   which   to   store   the   data   read   from   the                                                                                     '   drive.
    End Type
    Private Type ATTRTHRESHOLD
            bAttrID   As Byte                           '   Identifies   which   attribute
            bWarrantyThreshold   As Byte     '   Triggering   value
            bReserved(9)   As Byte               '   ...
    End TypePrivate Type IDSECTOR
            wGenConfig   As Integer
            wNumCyls   As Integer
            wReserved   As Integer
            wNumHeads   As Integer
            wBytesPerTrack   As Integer
            wBytesPerSector   As Integer
            wSectorsPerTrack   As Integer
            wVendorUnique(2)   As Integer
            sSerialNumber(19)   As Byte
            wBufferType   As Integer
            sFirmwareRev(7)   As Byte
            sModelNumber(39)   As Byte
    End TypePrivate Const VER_PLATFORM_WIN32s As Long = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1
    Private Const VER_PLATFORM_WIN32_NT As Long = 2
    Private Type OSVERSIONINFO
            dwOSVersionInfoSize   As Long
            dwMajorVersion   As Long
            dwMinorVersion   As Long
            dwBuildNumber   As Long
            dwPlatformId   As Long
            szCSDVersion   As String * 128                   '     Maintenance   string   for   PSS   usage
    End TypePrivate Declare Function GetVersionEx Lib "KERNEL32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Const GENERIC_READ       As Long = &H80000000
    Private Const GENERIC_WRITE       As Long = &H40000000
    Private Const OPEN_EXISTING         As Long = 3
    Private Declare Function CreateFile Lib "KERNEL32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function DeviceIoControl Lib "KERNEL32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
    Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
    Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
    Private m_DiskInfo As IDSECTORPrivate Function OpenSMART(ByVal nDrive As Byte) As Long
          Dim hSMARTIOCTL&, hd$
          Dim VersionInfo     As OSVERSIONINFO
          VersionInfo.dwOSVersionInfoSize = Len(VersionInfo)
          GetVersionEx VersionInfo
          Select Case VersionInfo.dwPlatformId
                Case VER_PLATFORM_WIN32s
                      OpenSMART = hSMARTIOCTL
                Case VER_PLATFORM_WIN32_WINDOWS
                      hSMARTIOCTL = CreateFile("\\.\SMARTVSD", 0, 0, 0, CREATE_NEW, 0, 0)
                Case VER_PLATFORM_WIN32_NT
                      If nDrive < MAX_IDE_DRIVES Then
                            hd = "\\.\PhysicalDrive" & nDrive
                            hSMARTIOCTL = CreateFile(hd, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
                      End If
          End Select
          OpenSMART = hSMARTIOCTL
    End FunctionPrivate Function DoIDENTIFY(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP() As Byte, ByVal bIDCmd As Byte, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As Boolean
          pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)
          pSCIP.irDriveRegs.bCommandReg = bIDCmd
          pSCIP.bDriveNumber = bDriveNum
          DoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, pSCIP, 32, pSCOP(0), 528, lpcbBytesReturned, 0))
    End FunctionPublic Function GetDiskInfo(ByVal nDrive As Byte) As Long
          Dim hSMARTIOCTL&, cbBytesReturned&
          Dim VersionParams     As GETVERSIONOUTPARAMS
          Dim scip     As SENDCMDINPARAMS
          Dim scop()     As Byte
          Dim OutCmd     As SENDCMDOUTPARAMS
          Dim bDfpDriveMap     As Byte
          Dim bIDCmd     As Byte                                           '   IDE   or   ATAPI   IDENTIFY   cmd
          Dim uDisk     As IDSECTOR
          m_DiskInfo = uDisk
          hSMARTIOCTL = OpenSMART(nDrive)
    '      If hSMARTIOCTL <> INVALID_HANDLE_VALUE Then
        If hSMARTIOCTL <> vbNull Then
    '            Call DeviceIoControl(hSMARTIOCTL, DFP_GET_VERSION, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)
                Call DeviceIoControl(hSMARTIOCTL, vbNull, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)
                bIDCmd = IIf((VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10), IDE_ATAPI_ID, IDE_ID_FUNCTION)
                ReDim scop(LenB(OutCmd) + IDENTIFY_BUFFER_SIZE - 1) As Byte
                If DoIDENTIFY(hSMARTIOCTL, scip, scop, bIDCmd, nDrive, cbBytesReturned) Then
                      CopyMemory m_DiskInfo, scop(LenB(OutCmd) - 4), LenB(m_DiskInfo)
                      CloseHandle hSMARTIOCTL
                      GetDiskInfo = 1
                      Exit Function
                End If
                CloseHandle hSMARTIOCTL
                GetDiskInfo = 0
          End If
    End Function
    Public Function GetDiskHardSerialNumber() As String
        Dim strP As String
        If GetDiskInfo(0) = 1 Then
            strP = Trim(StrConv(m_DiskInfo.sSerialNumber, vbUnicode))
            strP = Right("00000000" & strP, 8)
            GetDiskHardSerialNumber = Mid(strP, 2, 1) & Mid(strP, 1, 1) & Mid(strP, 4, 1) & Mid(strP, 3, 1) & Mid(strP, 6, 1) & Mid(strP, 5, 1) & Mid(strP, 8, 1) & Mid(strP, 7, 1)
            strP = "硬盘型号:" & StrConv(m_DiskInfo.sModelNumber, vbUnicode)
        Else
          GetDiskHardSerialNumber = "00000000"
        End If
    End Function
      

  3.   

    可以参看这个吧?:
    http://topic.csdn.net/t/20050704/08/4120593.html
      

  4.   

    If GetDiskInfo(0) = 1 Then
    修改这个:0 可以取得另外的硬盘
      

  5.   


    Private Sub Command1_Click()
       Dim WMI As Object
       Dim WMIObject As Object
       Dim ChildObject As Object
       Set WMI = GetObject("winmgmts://./root/cimv2")
       Set WMIObject = WMI.InstancesOf("Win32_DiskDrive")
       List1.Clear
       For Each ChildObject In WMIObject
          List1.AddItem "[" & ChildObject.Properties_.Item("InterfaceType").Value & "]" & _
                        "[" & ChildObject.Properties_.Item("Caption").Value & "]" & _
                        IIf(IsNull(ChildObject.Properties_.Item("Signature").Value) = True, "(NULL)", ChildObject.Properties_.Item("Signature").Value)
       Next
    End Sub
      

  6.   

    ChildObject.Properties_.Item("Signature").Value
      

  7.   

    除了 Signature 你认为还有什么?
    这是能列出来的所有与硬盘相关的属性,你看看哪个你认为比较像点
    Availability
    BytesPerSector
    Capabilities
    CapabilityDescriptions
    Caption
    CompressionMethod
    ConfigManagerErrorCode
    ConfigManagerUserConfig
    CreationClassName
    DefaultBlockSize
    Description
    DeviceID
    ErrorCleared
    ErrorDescription
    ErrorMethodology
    Index
    InstallDate
    InterfaceType
    LastErrorCode
    Manufacturer
    MaxBlockSize
    MaxMediaSize
    MediaLoaded
    MediaType
    MinBlockSize
    Model
    Name
    NeedsCleaning
    NumberOfMediaSupported
    Partitions
    PNPDeviceID
    PowerManagementCapabilities
    PowerManagementSupported
    SCSIBus
    SCSILogicalUnit
    SCSIPort
    SCSITargetId
    SectorsPerTrack
    Signature
    Size
    Status
    StatusInfo
    SystemCreationClassName
    SystemName
    TotalCylinders
    TotalHeads
    TotalSectors
    TotalTracks
    TracksPerCylinder
      

  8.   

    你试验过 Signature 吗?
    我用移动硬盘试验过,在其他机器上看到的值都是相同的
      

  9.   

    不过我是在IDE硬盘的环境下试验的
      

  10.   

    你是凭借什么理由判断 Signature 里的值不是所谓的硬盘 ID 号的呢?
      

  11.   

    Signature 只在驱动器信息中获得,而且不会收格式化分区影响,
    即使更换电脑来重新取得他的值也不会发生变化,而且在系统中的
    同类信息是唯一的,这已经完全具备了所谓硬盘 ID 的所有特点,
    再看其意:
    signature
    [ 5si^nitFE ]
    n.签名, 署名, 信号这就更可以认为他是所谓的硬盘 ID 了,即使不是,也可以当做这么用。
      

  12.   

    是不是WMI中的序列号经过加密了?
      

  13.   

    Veron_04  楼主啊  你七楼的代码不是已经解决你自己的问题了嘛
      

  14.   

    兄弟,这个代码在PATA硬盘下是没有问题的,但对SATA就不行了,所以求对SATA硬盘的方法。
      

  15.   


    你这个我测试的显示我的硬盘是IDE,怎么可能呢,我硬盘明明是SATA呀,半年前才配的西数500G绿盘,现在哪还有IDE的硬盘卖啊,明明是SATA的呀
      

  16.   

    楼主我是双硬盘,SATA+PATA,我使用您七楼的代码把两个盘的物理序列号全都成功读取出来了。
    为什么你得不到呢,奇怪了
      

  17.   

    stat基本上都读不出来,换方法吧反正我是想尽办法,查阅无数资料也没搞定过。
    即便偶尔成功1,2次,那也只能是偶尔。
      

  18.   

    Private Function CmnGetHDData(hdi As HDINFO) As String
        Call VarPtr("VMProtect begin")
        
        Dim bin As SENDCMDINPARAMS
        Dim bout As SENDCMDOUTPARAMS
        Dim hdh As Long
        Dim br As Long
        Dim ix As Long
        Dim hddfr As Long
        Dim hddln As Long
        Dim S As String
        
        Select Case hdi
        Case HD_MODEL_NUMBER
            hddfr = 55
            hddln = 40
        Case HD_SERIAL_NUMBER
            hddfr = 21
            hddln = 20
        Case HD_FIRMWARE_REVISION
            hddfr = 47
            hddln = 8
        Case Else
            Err.Raise 10001, "Illegal HD Data type"
        End Select
        
        Select Case mvarPlatform
        Case "WNT"
            hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
        Case "W95", "W98"
            hdh = CreateFile("\\.\Smartvsd", 0, 0, 0, Create_NEW, 0, 0)
        Case Else
            Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)"
        End Select
        
        If hdh = 0 Then
            Err.Raise 10003, , "Error on CreateFile"
        End If
        
        ZeroMemory bin, Len(bin)
        ZeroMemory bout, Len(bout)
        
        With bin
            .bDriveNumber = mvarCurrentDrive
            .cBufferSize = 512
            With .irDriveRegs
                If (mvarCurrentDrive And 1) Then
                    .bDriveHeadReg = &HB0
                Else
                    .bDriveHeadReg = &HA0
                End If
                .bCommandReg = &HEC
                .bSectorCountReg = 1
                .bSectorNumberReg = 1
            End With
        End With
        
        DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, bin, Len(bin), bout, Len(bout), br, 0
        
        S = vbNullString
        For ix = hddfr To hddfr + hddln - 1 Step 2
            If bout.bBuffer(ix + 1) = 0 Then Exit For
            S = S & Chr(bout.bBuffer(ix + 1))
            If bout.bBuffer(ix) = 0 Then Exit For
            S = S & Chr(bout.bBuffer(ix))
        Next ix
        
        CloseHandle hdh
        CmnGetHDData = Trim(S)
        
        Call VarPtr("VMProtect end")
    End Function
      

  19.   

    楼上的,你好!你的代码中:HDINFO和SENDCMDINPARAMS结构变量没有定义,我也查阅不到定义。HD_MODEL_NUMBER等常量也没有定义。请问怎么声明定义?
      

  20.   


    我没有测试过双硬盘,不过,我单独测试SATA是取不到SN的
      

  21.   

    我来发37楼的模块完整代码Option Explicit'Costanti per l 'individuazione della versione di OS
    Private Const VER_PLATFORM_WIN32S = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32_NT = 2'Costanti per la comunicazione con il driver IDE
    Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088'Costanti per la CreateFile
    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2
    Private Const GENERIC_READ = &H80000000
    Private Const GENERIC_WRITE = &H40000000
    Private Const OPEN_EXISTING = 3
    Private Const CREATE_NEW = 1'Enumerazione dei comandi per la CmnGetHDData
    Private Enum HDINFO
        HD_MODEL_NUMBER
        HD_SERIAL_NUMBER
        HD_FIRMWARE_REVISION
    End Enum'Struttura per l 'individuazione della versione di OS
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type'Struttura per il campo irDriveRegs della struttura SENDCMDINPARAMS
    Private Type IDEREGS
        bFeaturesReg As Byte
        bSectorCountReg As Byte
        bSectorNumberReg As Byte
        bCylLowReg As Byte
        bCylHighReg As Byte
        bDriveHeadReg As Byte
        bCommandReg As Byte
        bReserved As Byte
    End Type'Struttura per l 'I/O dei comandi al driver IDE
    Private Type SENDCMDINPARAMS
        cBufferSize As Long
        irDriveRegs As IDEREGS
        bDriveNumber As Byte
        bReserved(1 To 3) As Byte
        dwReserved(1 To 4) As Long
    End Type'Struttura per il campo DStatus della struttura SENDCMDOUTPARAMS
    Private Type DRIVERSTATUS
        bDriveError As Byte
        bIDEStatus As Byte
        bReserved(1 To 2) As Byte
        dwReserved(1 To 2) As Long
    End Type'Struttura per l 'I/O dei comandi al driver IDE
    Private Type SENDCMDOUTPARAMS
        cBufferSize As Long
        DStatus As DRIVERSTATUS 'ovvero DriverStatus
        bBuffer(1 To 512) As Byte
    End Type'Per ottenere la versione del SO
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long'Per ottenere un handle al device IDE
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long'Per chiudere l 'handle del device IDE
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long'Per comunicare con il driver IDE
    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long'Per azzerare buffer di scambio dati
    Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)'Per copiare porzioni di memoria
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Declare Function GetLastError Lib "kernel32" () As LongPrivate mvarCurrentDrive As Byte 'Drive corrente
    Private mvarPlatform As String 'Piattaforma usataPublic Property Get Copyright() As String    'Copyright
        Copyright = "HDSN Vrs. 1.00, 枕善居收藏整理"End Property'Metodo GetModelNumber
    Public Function GetModelNumber() As String    'Ottiene il ModelNumber
        GetModelNumber = CmnGetHDData(HD_MODEL_NUMBER)End Function'Metodo GetSerialNumber
    Public Function GetSerialNumber() As String    'Ottiene il SerialNumber
        GetSerialNumber = CmnGetHDData(HD_SERIAL_NUMBER)End Function'Metodo GetFirmwareRevision
    Public Function GetFirmwareRevision() As String    'Ottiene la FirmwareRevision
        GetFirmwareRevision = CmnGetHDData(HD_FIRMWARE_REVISION)End Function'Proprieta 'CurrentDrive
    Public Property Let CurrentDrive(ByVal vData As Byte)    'Controllo numero di drive fisico IDE
        If vData < 0 Or vData > 3 Then
            Err.Raise 10000, , "Illegal drive number" 'IDE drive 0..3
        End If    'Nuovo drive da considerare
        mvarCurrentDrive = vDataEnd Property'Proprieta 'CurrentDrive
    Public Property Get CurrentDrive() As Byte    'Restituisce drive fisico corrente (IDE 0..3)
        CurrentDrive = mvarCurrentDriveEnd Property'Proprieta 'Platform
    Public Property Get Platform() As String    'Restituisce tipo OS
        Platform = mvarPlatformEnd PropertyPrivate Sub Class_Initialize()    'Individuazione del tipo di OS
        Dim OS As OSVERSIONINFO    OS.dwOSVersionInfoSize = Len(OS)
        Call GetVersionEx(OS)
        mvarPlatform = "Unk"
        Select Case OS.dwPlatformId
            Case Is = VER_PLATFORM_WIN32S
                mvarPlatform = "32S" 'Win32S
            Case Is = VER_PLATFORM_WIN32_WINDOWS
                If OS.dwMinorVersion = 0 Then
                    mvarPlatform = "W95" 'Win 95
                Else
                    mvarPlatform = "W98" 'Win 98
                End If
            Case Is = VER_PLATFORM_WIN32_NT
                mvarPlatform = "WNT" 'Win NT/2000
        End SelectEnd SubPrivate Function CmnGetHDData(hdi As HDINFO) As String    'Rilevazione proprieta 'IDE    Dim bin As SENDCMDINPARAMS
        Dim bout As SENDCMDOUTPARAMS
        Dim hdh As Long
        Dim br As Long
        Dim ix As Long
        Dim hddfr As Long
        Dim hddln As Long
        Dim s As String    Select Case hdi 'Selezione tipo caratteristica richiesta
            Case HD_MODEL_NUMBER
                hddfr = 55 'Posizione nel buffer del ModelNumber
                hddln = 40 'Lunghezza nel buffer del ModelNumber
            Case HD_SERIAL_NUMBER
                hddfr = 21 'Posizione nel buffer del SerialNumber
                hddln = 20 'Lunghezza nel buffer del SerialNumber
            Case HD_FIRMWARE_REVISION
                hddfr = 47 'Posizione nel buffer del FirmwareRevision
                hddln = 8 'Lunghezza nel buffer del FirmwareRevision
            Case Else
                Err.Raise 10001, "Illegal HD Data type" 'Altre informazioni non disponibili (Evoluzione futura)
        End Select    Select Case mvarPlatform
            Case "WNT"
                'Per Win NT/2000 apertura handle al drive fisico
                hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, _
                        FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
            Case "W95", "W98"
                'Per Win 9X apertura handle al driver SMART
                '(in \WINDOWS\SYSTEM da spostare in \WINDOWS\SYSTEM\IOSUBSYS)
                'che comunica con il driver IDE
                hdh = CreateFile("\\.\Smartvsd", 0, 0, 0, CREATE_NEW, 0, 0)
            Case Else
                'Piattaforma non supportata (Win32S)
                Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)" 'Altre piattaforme non gestite
        End Select
        'Controllo validit?handle
        If hdh = 0 Then
            Err.Raise 10003, , "Error on CreateFile"
        End If    'Azzeramento strutture per l 'I/O da driver
        ZeroMemory bin, Len(bin)
        ZeroMemory bout, Len(bout)    'Preparazione parametri struttura di richiesta al driver
        With bin
            .bDriveNumber = mvarCurrentDrive
            .cBufferSize = 512
            With .irDriveRegs
                If (mvarCurrentDrive And 1) Then
                    .bDriveHeadReg = &HB0
                Else
                    .bDriveHeadReg = &HA0
                End If
                .bCommandReg = &HEC
                .bSectorCountReg = 1
                .bSectorNumberReg = 1
            End With
        End With    'Richiesta al driver
        DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, bin, Len(bin), bout, Len(bout), br, 0    'Formazione stringa di risposta
        'da buffer di uscita
        'L 'ordine dei byte e 'invertito
        s = ""
        For ix = hddfr To hddfr + hddln - 1 Step 2
            If bout.bBuffer(ix + 1) = 0 Then Exit For
            s = s & Chr(bout.bBuffer(ix + 1))
            If bout.bBuffer(ix) = 0 Then Exit For
            s = s & Chr(bout.bBuffer(ix))
        Next ix    'Chiusura handle
        CloseHandle hdh    'Restituzione informazione richiesta
        CmnGetHDData = Trim(s)End Function'e.g:
    '    Dim hdi As New clsHardDiskInfo 'clsHardDiskInfo 这个是类模块的名称
    '    With hdi
    '        .CurrentDrive = 0
    '        Debug.Print "当前驱动器: " & .CurrentDrive
    '        Debug.Print ""
    '        Debug.Print "硬盘型号: " & .GetModelNumber
    '        Debug.Print "序列号: " & .GetSerialNumber
    '        Debug.Print "固件版本: " & .GetFirmwareRevision
    '    End With
      

  22.   

    请问楼主您的硬盘是哪个品牌什么型号的SATA硬盘啊????
      

  23.   

    我的也是希捷的啊 ST3500320AS 、 ST3320620AV  两块  前者是SATA  后者是PATA
      

  24.   

    .CurrentDrive = 0
    后面又print "当前驱动器: " & .CurrentDrive
    什么意思,是不是有2块硬盘就.CurrentDrive = 1 ??
      

  25.   

    无论串口硬盘与并口硬盘,都支持SMART接口的,那就可以利用这个接口。原理是,使用DriviceIOControl向硬盘发送相应的指令,即可得到对应的信息。以下代码是从高手陆麟(lu0)写的C++版代码翻译而成,在我的机器中能得到硬盘序列号,硬盘是串口的。第一部分:Option Explicit
    '****************************************************************
    '原作: Bardo
    '出处: 《东方热讯》网站
    '网址: www.easthot.net
    '****************************************************************
    '(如需转载,请不在删除以上信息,否则视为侵权!)
    '****************************************************************
    '要这个有什么用?可以生成与硬件相关的注册码。控制软件不重复使用!那么,很多多人认为VB实现不了。自然没有找到方法,一定是实现不了。然而,感谢WWW,我们能在上面找到VC的源码,DELPHI的源码。但是VB的就是见不到。为此,我决定将VC的源码改成VB的,以下即是:'VC原作说明部分(再发行时,请注意采用注解的方式,请不要删除的方式侵权,谢谢!)
    '*************************************************************************
    '通常情况下,我们通过=&HEC命令对IDE端口进行监测.获取硬盘信息.
    '一般情况下,我们就写个VXD或者DRIVER来完成.但是现在,通过MS的S.M.A.R.T.接口,
    '我们可以直接从RING3调用API DeviceIoControl()来获取硬盘信息.下面乃是我的例程:
    '另外,也有编译好的版本供大家平时使用.欢迎下载.
    '/*+++
    'HDID.CPP
    'Written by Lu Lin
    'http://lu0.126.com
    '2000.11.3
    '---*/
    '*************************************************************************
    'VB程序编制: BARDO
    '本来我想写一个只取盘动物理序列号的。但是考虑到大家学习的方便。还是将原来的代码
    '全部翻译了出来。如果你需要单一的只查一个主硬盘的序列号的程序,欢迎到本站下载。
    '
    '网站:东方热讯:http://www.easthot.net
    '邮件:[email protected]
    '2003.01.23
    '*************************************************************************
    '以下这一行是必须的,困为要做结构复制。而结构中有数组。所以,没有它则会错位
    Option Base 0Private Const DFP_GET_VERSION = &H74080
    Private Const DFP_SEND_DRIVE_COMMAND = &H7C084
    Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088'#pragma pack(1)
    Private Type TGETVERSIONOUTPARAMS   '{
        bVersion As Byte  'Binary driver version.
        bRevision As Byte 'Binary driver revision.
        bReserved As Byte  'Not used.
        bIDEDeviceMap As Byte 'Bit map of IDE devices.
        fCapabilities As Long 'Bit mask of driver capabilities.
        dwReserved(4) As Long 'For future use.
    End TypePrivate Type TIDEREGS
        bFeaturesReg As Byte   'Used for specifying SMART "commands".
        bSectorCountReg As Byte  'IDE sector count register
        bSectorNumberReg As Byte  'IDE sector number register
        bCylLowReg As Byte    'IDE low order cylinder value
        bCylHighReg As Byte   'IDE high order cylinder value
        bDriveHeadReg As Byte   'IDE drive/head register
        bCommandReg As Byte   'Actual IDE command.
        bReserved As Byte    'reserved for future use.  Must be zero.
    End TypePrivate Type TSENDCMDINPARAMS
        cBufferSize As Long   'Buffer size in bytes
        irDriveRegs As TIDEREGS   'Structure with drive register values.
        bDriveNumber As Byte   'Physical drive number to send  'command to (0,1,2,3).
        bReserved(2) As Byte   'Reserved for future expansion.
        dwReserved(3) As Long   'For future use.
        ''BYTE  bBuffer(1)   'Input buffer.
    End TypePrivate Type TDRIVERSTATUS
        bDriverError As Byte  'Error code from driver, 'or 0 if no error.
        bIDEStatus  As Byte  'Contents of IDE Error register.
               'Only valid when bDriverError 'is SMART_IDE_ERROR.
        bReserved(1) As Byte   'Reserved for future expansion.
        dwReserved(1) As Long   'Reserved for future expansion.
    End TypePrivate Type TSENDCMDOUTPARAMS
        cBufferSize As Long      'Size of bBuffer in bytes
        DRIVERSTATUS As TDRIVERSTATUS   'Driver status structure.
        bBuffer(511) As Byte   'Buffer of arbitrary length
                 'in which to store the data read from the drive.
    End Type'下面的结构是要从另一结构复制数据过来的,所以,必须是字节数与VC的完全一致
    '而不能用兼容变量,但这里的我们还是用了兼容变量,Integer,因为此结构中这一
    '类型的的变量程序中没有用到,如果要用到,建议改为Byte类型。因为VB没有USHORTPrivate Type TIDSECTOR
        wGenConfig As Integer
        wNumCyls As Integer
        wReserved As Integer
        wNumHeads As Integer
        wBytesPerTrack As Integer
        wBytesPerSector As Integer
        wSectorsPerTrack As Integer
        wVendorUnique(2) As Integer
        sSerialNumber(19) As Byte
        wBufferType As Integer
        wBufferSize As Integer
        wECCSize As Integer
        sFirmwareRev(7) As Byte
        sModelNumber(39) As Byte
        wMoreVendorUnique As Integer
        wDoubleWordIO As Integer
        wCapabilities As Integer
        wReserved1 As Integer
        wPIOTiming As Integer
        wDMATiming As Integer
        wBS As Integer
        wNumCurrentCyls As Integer
        wNumCurrentHeads As Integer
        wNumCurrentSectorsPerTrack As Integer
        ulCurrentSectorCapacity(3) As Byte   '这里只能用byte,因为VB没有无符号的LONG型变量
        wMultSectorStuff As Integer
        ulTotalAddressableSectors(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量
        wSingleWordDMA As Integer
        wMultiWordDMA As Integer
        bReserved(127) As Byte
    End Type'/*+++
    'Global vars
    '---*/
    Private vers As TGETVERSIONOUTPARAMS
    Private in_data As TSENDCMDINPARAMS
    Private out_data As TSENDCMDOUTPARAMS
    Private h As Long
    Private I As Long
    Private J As BytePrivate Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End TypePrivate Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
              (LpVersionInformation As OSVERSIONINFO) As LongPrivate Const VER_PLATFORM_WIN32S = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32_NT = 2Private Declare Function CreateFile Lib "kernel32" _
        Alias "CreateFileA" (ByVal lpFileName As String, _
        ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
        ByVal lpSecurityAttributes As Long, _
        ByVal dwCreationDisposition As Long, _
        ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) _
        As LongPrivate Const CREATE_NEW = 1
    Private Const GENERIC_READ = &H80000000
    Private Const GENERIC_WRITE = &H40000000
    Private Const OPEN_EXISTING = 3
    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2Private Type OVERLAPPED
        Internal As Long
        InternalHigh As Long
        offset As Long
        OffsetHigh As Long
        hEvent As Long
    End TypePrivate Declare Function DeviceIoControl Lib "kernel32" _
        (ByVal hDevice As Long, ByVal dwIoControlCode As Long, _
        lpInBuffer As Any, ByVal nInBufferSize As Long, _
        lpOutBuffer As Any, ByVal nOutBufferSize As Long, _
        lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
             hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    Private Sub CopyRight()
        'VC原版权代码(再发行时,请注意采用注解的方式,请不要删除的方式侵权,谢谢!)
        '****************************************************************************
        ' cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl
        ' cerr<<"For more information, please visit Inside Programming: http:'lu0.126.com"<<endl
        ' cerr<<"2000.11.3"<<endl<<endl
        '****************************************************************************
        Dim StrMsg As String
        StrMsg = StrMsg & "直接从RING3调用API DeviceIoControl()来获取硬盘信息的VB程序 "
        StrMsg = StrMsg & vbCrLf & "VC源作板权信息如下:"
        StrMsg = StrMsg & vbCrLf & "***********************************************************"
        StrMsg = StrMsg & vbCrLf & "HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"
        StrMsg = StrMsg & vbCrLf & "For more information, please visit Inside Programming: http://lu0.126.com"
        StrMsg = StrMsg & vbCrLf & "2000.11.3"
        StrMsg = StrMsg & vbCrLf & "***********************************************************"
        StrMsg = StrMsg & vbCrLf & "VB程序编制:BARDO"
        StrMsg = StrMsg & vbCrLf & "网站:东方热讯:http://www.easthot.net"
        StrMsg = StrMsg & vbCrLf & "邮件:[email protected]"
        StrMsg = StrMsg & vbCrLf & "2003.01.23"
        MsgBox StrMsg
    End SubSub ChangeByteOrder(szString() As Byte, uscStrSize As Long)
        Dim I As Long
        Dim Temp As String
         For I = 0 To uscStrSize - 1 Step 2
            Temp = szString(I)
            szString(I) = szString(I + 1)
            szString(I + 1) = Temp
         Next I
    End Sub
      

  26.   

    第二部分:Private Function hdid9x() As String'We start in 95/98/Me
    h = CreateFile("\\.\Smartvsd", 0, 0, 0, CREATE_NEW, 0, 0)
    If h = 0 Then
        hdid9x = "open smartvsd.vxd failed"
        Exit Function
    End IfDim olp As OVERLAPPED
    Dim lRet As Long
    lRet = DeviceIoControl(h, DFP_GET_VERSION, ByVal 0&, 0, vers, Len(vers), ByVal I, olp)
    If lRet = 0 Then
            hdid9x = "DeviceIoControl failed:DFP_GET_VERSION"
            CloseHandle (h)
            Exit Function
    End If'If IDE identify command not supported, fails
    If (vers.fCapabilities And 1) <> 1 Then
        hdid9x = "Error: IDE identify command not supported."
        CloseHandle (h)
        Exit Function
    End If'Display IDE drive number detected
    Dim sPreOutStr As String
    sPreOutStr = DetectIDE(vers.bIDEDeviceMap)
    hdid9x = sPreOutStr'Identify the IDE drives
    For J = 0 To 3
        Dim phdinfo As TIDSECTOR
        Dim S(40) As Byte
        
        If (J And 1) = 1 Then
            in_data.irDriveRegs.bDriveHeadReg = &HB0
        Else
            in_data.irDriveRegs.bDriveHeadReg = &HA0
        End If
        If (vers.fCapabilities And (16 \ (2 ^ J))) = (16 \ (2 ^ J)) Then
            'We don't detect a ATAPI device.
            hdid9x = "Drive " & CStr(J + 1) & " is a ATAPI device, we don't detect it"
        Else
              in_data.irDriveRegs.bCommandReg = &HEC
              in_data.bDriveNumber = J
              in_data.irDriveRegs.bSectorCountReg = 1
              in_data.irDriveRegs.bSectorNumberReg = 1
              in_data.cBufferSize = 512
              
              lRet = DeviceIoControl(h, DFP_RECEIVE_DRIVE_DATA, in_data, Len(in_data), out_data, Len(out_data), ByVal I, olp)
              
              If lRet = 0 Then
                  hdid9x = "DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"
                  CloseHandle (h)
                  Exit Function
              End If
              
              Dim StrOut As String
              
              CopyMemory phdinfo, out_data.bBuffer(0), Len(phdinfo)
              
              CopyMemory S(0), phdinfo.sModelNumber(0), 40
              S(40) = 0
              ChangeByteOrder S, 40
              
              StrOut = ByteArrToString(S, 40)
              
              hdid9x = hdid9x & vbCrLf & "Module Number:" & StrOut
              CopyMemory S(0), phdinfo.sFirmwareRev(0), 8
              S(8) = 0
              ChangeByteOrder S, 8
              
              StrOut = ByteArrToString(S, 8)
              
              hdid9x = hdid9x & vbCrLf & "Firmware rev:" & StrOut
              CopyMemory S(0), phdinfo.sSerialNumber(0), 20
              S(20) = 0
              ChangeByteOrder S, 20
              
              StrOut = ByteArrToString(S, 20)
              
              hdid9x = hdid9x & vbCrLf & "Serial Number:" & StrOut
              
              CopyMemory S(0), phdinfo.ulTotalAddressableSectors(0), 4
              
              S(5) = 0
              Dim dblStrOut As Double
              dblStrOut = ByteArrToLong(S)
              hdid9x = hdid9x & vbCrLf & "Capacity:" & dblStrOut / 2 / 1024 & "M"
          End If
    Next J'Close handle before quit
    CloseHandle (h)
    CopyRightEnd FunctionPrivate Function hdidnt(ByRef outHDDID() As String) As String
    Dim hd As String * 80
    Dim phdinfo As TIDSECTOR
    Dim S(40) As Byte
    Dim StrOut As StringReDim outHDDID(4)hdidnt = ""
    'We start in NT/Win2000For J = 0 To 3  '这里取四个硬盘的信息,因为正常PC不超过四个硬盘
         hd = "\\.\PhysicalDrive" & CStr(J)
         hdidnt = hdidnt & vbCrLf & hd
         h = CreateFile(hd, GENERIC_READ Or GENERIC_WRITE, _
              FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
         
         Dim olpv As OVERLAPPED
         
         Dim lRet As Long
         lRet = DeviceIoControl(h, DFP_GET_VERSION, ByVal 0&, 0, vers, Len(vers), ByVal I, olpv)
         
         If lRet = 0 Then
             CloseHandle (h)
         Else
                'If IDE identify command not supported, fails
                If (vers.fCapabilities And 1) <> 1 Then
                      hdidnt = "Error: IDE identify command not supported."
                      CloseHandle (h)
                      Exit Function
                End If
                'Identify the IDE drives
                If (J And 1) = 1 Then
                    in_data.irDriveRegs.bDriveHeadReg = &HB0
                Else
                    in_data.irDriveRegs.bDriveHeadReg = &HA0
                End If
                If (vers.fCapabilities And (16 \ (2 ^ J))) <> 0 Then
                    'We don't detect a ATAPI device.
                    hdidnt = hdidnt & vbCrLf & "Drive " & CStr(J + 1) & " is a ATAPI device, we don't detect it"
                Else
                      
                      in_data.irDriveRegs.bCommandReg = &HEC
                      in_data.bDriveNumber = J
                      in_data.irDriveRegs.bSectorCountReg = 1
                      in_data.irDriveRegs.bSectorNumberReg = 1
                      in_data.cBufferSize = 512
                      
                      Dim olpr As OVERLAPPED
                      
                      lRet = DeviceIoControl(h, DFP_RECEIVE_DRIVE_DATA, in_data, Len(in_data), out_data, Len(out_data), ByVal I, olpr)
                      If lRet <= 0 Then
                           hdidnt = hdidnt & vbCrLf & "DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"
                           CloseHandle (h)
                           
                      Else
                   
                         CopyMemory phdinfo, out_data.bBuffer(0), Len(phdinfo)
                         
                         CopyMemory S(0), phdinfo.sModelNumber(0), 40
                         S(40) = 0
                         ChangeByteOrder S, 40
                         
                         StrOut = ByteArrToString(S, 40)
                         
                         hdidnt = hdidnt & vbCrLf & "Module Number:" & StrOut
                         CopyMemory S(0), phdinfo.sFirmwareRev(0), 8
                         S(8) = 0
                         ChangeByteOrder S, 8
                         
                         StrOut = ByteArrToString(S, 8)
                         
                         hdidnt = hdidnt & vbCrLf & "Firmware rev:" & StrOut
                         CopyMemory S(0), phdinfo.sSerialNumber(0), 20
                         S(20) = 0
                         ChangeByteOrder S, 20
                         
                         StrOut = ByteArrToString(S, 20)
                         
                         hdidnt = hdidnt & vbCrLf & "Serial Number:" & StrOut
                         outHDDID(J + 1) = Trim(StrOut)
                         
                         CopyMemory S(0), phdinfo.ulTotalAddressableSectors(0), 4
                         S(5) = 0
                         Dim dblStrOut As Double
                         dblStrOut = ByteArrToLong(S)
                         
                         hdidnt = hdidnt & vbCrLf & "Capacity:" & dblStrOut / 2 / 1024 & "M"
                         CloseHandle (h)
                      End If
                End If
           End If
    Next J
    'CopyRightEnd FunctionPrivate Function DetectIDE(bIDEDeviceMap As Byte) As String
        If (bIDEDeviceMap And 1) Then
            If (bIDEDeviceMap And 16) Then
                 DetectIDE = DetectIDE & "ATAPI device is attached to primary controller, drive 0."
            Else
                 DetectIDE = DetectIDE & "IDE device is attached to primary controller, drive 0."
            End If
        End If
        If (bIDEDeviceMap And 2) Then
            If (bIDEDeviceMap And 32) Then
                 DetectIDE = DetectIDE & "ATAPI device is attached to primary controller, drive 1."
            Else
                 DetectIDE = DetectIDE & "IDE device is attached to primary controller, drive 1."
            End If
        End If
        If (bIDEDeviceMap And 4) Then
            If (bIDEDeviceMap And 64) Then
                 DetectIDE = DetectIDE & "ATAPI device is attached to secondary controller, drive 0."
            Else
                 DetectIDE = DetectIDE & "IDE device is attached to secondary controller, drive 0."
            End If
        End If
        If (bIDEDeviceMap And 8) Then
            If (bIDEDeviceMap And 128) Then
                 DetectIDE = DetectIDE & "ATAPI device is attached to secondary controller, drive 1."
            Else
                 DetectIDE = DetectIDE & "IDE device is attached to secondary controller, drive 1."
            End If
        End If
    End FunctionPrivate Function ByteArrToString(inByte() As Byte, ByVal strlen As Integer) As String
        Dim I As Integer
        For I = 0 To strlen
            If inByte(I) = 0 Then
               Exit For
            End If
            ByteArrToString = ByteArrToString & Chr(inByte(I))
        Next I
    End FunctionPrivate Function ByteArrToLong(inByte() As Byte) As Double
        Dim I As Integer
        For I = 0 To 3
            ByteArrToLong = ByteArrToLong + CDbl(inByte(I)) * (256 ^ I)
        Next I
    End FunctionPublic Function GetHDDID(ByVal HDDIndex As Long, Optional ByRef outFullInfo As String = "-1") As String
        '取硬盘ID
        'HDDIndex - 硬盘号(1 - 4)
        'outFullInfo - 可选,输出;用于输出完整的硬盘信息
        '返回值:
        '       指定硬盘的ID
        Dim VerInfo As OSVERSIONINFO
        Dim Ret As Long, I As Long, J As Long, K As Long
        Dim strInfo As String, strInfoArr() As String
        
        VerInfo.dwOSVersionInfoSize = Len(VerInfo)
        Ret = GetVersionEx(VerInfo)
        
        Select Case VerInfo.dwPlatformId
        Case VER_PLATFORM_WIN32S
            strInfo = "Win32s is not supported by this programm."
        Case VER_PLATFORM_WIN32_WINDOWS
            strInfo = hdid9x
        Case VER_PLATFORM_WIN32_NT
            strInfo = hdidnt(strInfoArr)
        End Select
        If outFullInfo <> "-1" Then outFullInfo = strInfo
        GetHDDID = strInfoArr(HDDIndex)
    End Function
    调用:
    msgbox GetHDDID(1)
    GetHDDID函数是我添加的,封装得更简单点,比较适合我。另外,我还收藏了一个,刚试了一下,也可以取到我的硬盘ID:http://www.m5home.com/bbs/thread-367-1-3.html试一下吧。
      

  27.   

    楼主,说出来可能打击你,其实上面的所有人发的代码我机器上运行都返回了正确的序列号,我硬盘就是SATA的,所以原因是你的机器问题不是代码问题吧还有老马那个,请问cbDrive是怎么获得4个选项的???没找到那里设置的
      

  28.   

    机器原因也有可能。另外,ComboBox的List属性是设置内容的
      

  29.   

    西数sataII 接口 640g 黑盘 以上所有方法得不到任何信息
      

  30.   

    WIN7-64位未试过,我这里只有2003-32位。
      

  31.   

    windows7 32位 旗舰版 
      

  32.   

    以上所有代码均可在 Windows7 32位 旗舰版下获得SATA硬盘物理序列号,报告完毕。
      

  33.   

    楼主,我有一个第三方的 .dll ,免费的。
    最近好象在网上找不到了。我试过可以取得串口硬盘的物理序号。
    楼主有兴趣,可以把你的邮箱M给我,我给你写个简单的示例,与那个 dll文件一起发给你。只是不知道你的环境下能不能正确取得。
    我测试过的系统也是32位的。
      

  34.   

    最近经常潜水……
    虽然结贴了,还是给你写了个应用示例,与那个 .dll 文件一起打包发给你了。全部代码就这点儿:
    '工程引用: ReYoDisk.dll
    Option ExplicitPrivate Sub Form_Load()
       Dim objDiskInfo As New DiskInfo
       AutoRedraw = True
       FontSize = 13
       objDiskInfo.CurrentDrive = 0  '0表示第一块物理硬盘 
       Print
       Print "磁盘型号:" & Chr$(9) & objDiskInfo.GetDiskMode
       Print "磁盘物理序号:" & Chr$(9) & objDiskInfo.GetDiskSerialNumber
       Print "固件版本:" & Chr$(9) & objDiskInfo.GetFirmwareRevision
       Set objDiskInfo = Nothing
    End Sub