⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdiskinfo.cls

📁 读取磁盘序列号 读取磁盘序列号 读取磁盘序列号
💻 CLS
📖 第 1 页 / 共 2 页
字号:
    Case VER_PLATFORM_WIN32s
        OpenSMART = hSMARTIOCTL
    Case VER_PLATFORM_WIN32_WINDOWS
        ' Version Windows 95 OSR2, Windows 98
        hSMARTIOCTL = CreateFile("\\.\SMARTVSD", 0, 0, 0, CREATE_NEW, 0, 0)
    Case VER_PLATFORM_WIN32_NT
        ' Windows NT, Windows 2000
        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 Function

'/****************************************************************************
'*
'* DoIDENTIFY
'*
'* FUNCTION: Send an IDENTIFY command to the drive
'* bDriveNum = 0-3
'* bIDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
'*
'****************************************************************************/
Private 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
    '
    ' Set up data structures for IDENTIFY command.
    '

    pSCIP.cBufferSize = IDENTIFY_BUFFER_SIZE

    pSCIP.irDriveRegs.bFeaturesReg = 0
    pSCIP.irDriveRegs.bSectorCountReg = 1
    pSCIP.irDriveRegs.bSectorNumberReg = 1
    pSCIP.irDriveRegs.bCylLowReg = 0
    pSCIP.irDriveRegs.bCylHighReg = 0

    '
    ' Compute the drive number.
    '
    pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)

    '
    ' The command can either be IDE identify or ATAPI identify.
    '
    pSCIP.irDriveRegs.bCommandReg = bIDCmd
    pSCIP.bDriveNumber = bDriveNum
    pSCIP.cBufferSize = IDENTIFY_BUFFER_SIZE
    
    DoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, _
                pSCIP, LenB(pSCIP) - 1, _
                pSCOP(0), UBound(pSCOP), _
                lpcbBytesReturned, 0))
End Function


'/****************************************************************************
'*
'* DoEnableSMART
'*
'* FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
'* bDriveNum = 0-3
'*
'****************************************************************************/
Private Function DoEnableSMART(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP As SENDCMDOUTPARAMS, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As Boolean
    '
    ' Set up data structures for Enable SMART Command.
    '
    pSCIP.cBufferSize = 0

    pSCIP.irDriveRegs.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONS
    pSCIP.irDriveRegs.bSectorCountReg = 1
    pSCIP.irDriveRegs.bSectorNumberReg = 1
    pSCIP.irDriveRegs.bCylLowReg = SMART_CYL_LOW
    pSCIP.irDriveRegs.bCylHighReg = SMART_CYL_HI

    '
    ' Compute the drive number.
    '
    pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)
    pSCIP.irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTION
    pSCIP.bDriveNumber = bDriveNum

    DoEnableSMART = CBool(DeviceIoControl(hSMARTIOCTL, DFP_SEND_DRIVE_COMMAND, _
                pSCIP, LenB(pSCIP) - 1, _
                pSCOP, LenB(pSCOP) - 1, _
                lpcbBytesReturned, 0))
End Function

'---------------------------------------------------------------------
'---------------------------------------------------------------------
Private Sub ChangeByteOrder(szString() As Byte, ByVal uscStrSize As Integer)

    Dim i As Integer
    Dim bTemp As Byte

    For i = 0 To uscStrSize - 1 Step 2
        bTemp = szString(i)
        szString(i) = szString(i + 1)
        szString(i + 1) = bTemp
    Next i
End Sub

'/****************************************************************************
'*
'* DisplayIdInfo
'*
'* Display the contents of the ID buffer
'*
'****************************************************************************/
Private Sub DisplayIdInfo(pids As IDSECTOR, pSCIP As SENDCMDINPARAMS, ByVal bIDCmd As Byte, ByVal bDfpDriveMap As Byte, ByVal bDriveNum As Byte)
    ChangeByteOrder pids.sModelNumber, UBound(pids.sModelNumber) + 1

    ChangeByteOrder pids.sFirmwareRev, UBound(pids.sFirmwareRev) + 1

    ChangeByteOrder pids.sSerialNumber, UBound(pids.sSerialNumber) + 1
End Sub
Public Function GetDiskInfo(ByVal nDrive As Byte) As Long
    Dim hSMARTIOCTL As Long
    Dim cbBytesReturned As Long
    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
    ' Clear buffer
    m_DiskInfo = uDisk
    '
    ' Try to get a handle to SMART IOCTL, report failure and exit if
    ' can't.
    '
    hSMARTIOCTL = OpenSMART(nDrive)
    If hSMARTIOCTL <> INVALID_HANDLE_VALUE Then
        '
        ' Get the version, etc of SMART IOCTL
        '

        Call DeviceIoControl(hSMARTIOCTL, DFP_GET_VERSION, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)

        '
        ' If there is a IDE device at number "nDrive" issue commands
        ' to the device.
        '
        'if (VersionParams.bIDEDeviceMap >> nDrive & 1)
        '{

        '
        ' Try to enable SMART so we can tell if a drive supports it.
        ' Ignore ATAPI devices.
        '

        If Not (VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10) Then
            If DoEnableSMART(hSMARTIOCTL, scip, OutCmd, nDrive, cbBytesReturned) Then
                '
                ' Mark the drive as SMART enabled
                '
                bDfpDriveMap = bDfpDriveMap Or 2 ^ nDrive
            End If
        End If


        '
        ' Now, get the ID sector for all IDE devices in the system.
        ' If the device is ATAPI use the IDE_ATAPI_ID command,
        ' otherwise use the IDE_ID_FUNCTION command.
        '
        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)
            Call DisplayIdInfo(m_DiskInfo, scip, bIDCmd, bDfpDriveMap, nDrive)
            '
            ' Close SMART.
            '
            CloseHandle hSMARTIOCTL
            GetDiskInfo = 1
            Exit Function
        End If
        '}
        '
        ' Close SMART.
        '
        CloseHandle hSMARTIOCTL
        GetDiskInfo = 0
    Else
        GetDiskInfo = -1
    End If
End Function

Public Property Get pGenConfig() As Long
    pGenConfig = VBIntegerToUShort(m_DiskInfo.wGenConfig)
End Property

Public Property Get pNumCyls() As Long
    pNumCyls = VBIntegerToUShort(m_DiskInfo.wNumCyls)
End Property

Public Property Get pNumHeads() As Long
    pNumHeads = VBIntegerToUShort(m_DiskInfo.wNumHeads)
End Property

Public Property Get pBytesPerTrack() As Long
    pBytesPerTrack = VBIntegerToUShort(m_DiskInfo.wBytesPerTrack)
End Property

Public Property Get pBytesPerSector() As Long
    pBytesPerSector = VBIntegerToUShort(m_DiskInfo.wBytesPerSector)
End Property

Public Property Get pSectorsPerTrack() As Long
    pSectorsPerTrack = VBIntegerToUShort(m_DiskInfo.wSectorsPerTrack)
End Property

Public Property Get pSerialNumber() As Byte()
    pSerialNumber = m_DiskInfo.sSerialNumber
End Property

Public Property Get pBufferType() As Long
    pBufferType = VBIntegerToUShort(m_DiskInfo.wBufferType)
End Property

Public Property Get pBufferSize() As Long
    pBufferSize = VBIntegerToUShort(m_DiskInfo.wBufferSize)
End Property

Public Property Get pECCSize() As Long
    pECCSize = VBIntegerToUShort(m_DiskInfo.wECCSize)
End Property

Public Property Get pFirmwareRev() As Byte()
    pFirmwareRev = m_DiskInfo.sFirmwareRev
End Property

Public Property Get pModelNumber() As Byte()
    pModelNumber = m_DiskInfo.sModelNumber
End Property

Public Property Get pDoubleWordIO() As Long
    pDoubleWordIO = VBIntegerToUShort(m_DiskInfo.wDoubleWordIO)
End Property

Public Property Get pCapabilities() As Long
    pCapabilities = VBIntegerToUShort(m_DiskInfo.wCapabilities)
End Property

Public Property Get pPIOTiming() As Long
    pPIOTiming = VBIntegerToUShort(m_DiskInfo.wPIOTiming)
End Property

Public Property Get pDMATiming() As Long
    pDMATiming = VBIntegerToUShort(m_DiskInfo.wDMATiming)
End Property

Public Property Get pBS() As Long
    pBS = VBIntegerToUShort(m_DiskInfo.wBS)
End Property

Public Property Get pNumCurrentCyls() As Long
    pNumCurrentCyls = VBIntegerToUShort(m_DiskInfo.wNumCurrentCyls)
End Property

Public Property Get pNumCurrentHeads() As Long
    pNumCurrentHeads = VBIntegerToUShort(m_DiskInfo.wNumCurrentHeads)
End Property

Public Property Get pNumCurrentSectorsPerTrack() As Long
    pNumCurrentSectorsPerTrack = VBIntegerToUShort(m_DiskInfo.wNumCurrentSectorsPerTrack)
End Property

Public Property Get pCurrentSectorCapacity() As Long
    pCurrentSectorCapacity = m_DiskInfo.ulCurrentSectorCapacity
End Property

Public Property Get pMultSectorStuff() As Long
    pMultSectorStuff = VBIntegerToUShort(m_DiskInfo.wMultSectorStuff)
End Property

Public Property Get pTotalAddressableSectors() As Long
    pTotalAddressableSectors = m_DiskInfo.ulTotalAddressableSectors
End Property

Public Property Get pSingleWordDMA() As Long
    pSingleWordDMA = VBIntegerToUShort(m_DiskInfo.wSingleWordDMA)
End Property

Public Property Get pMultiWordDMA() As Long
    pMultiWordDMA = VBIntegerToUShort(m_DiskInfo.wMultiWordDMA)
End Property

Private Function VBIntegerToUShort(ByVal i As Integer) As Long
    Call CopyMemory(VBIntegerToUShort, i, 2)
End Function






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -