续二: '取得逻辑盘序列号(非唯一) Function GetDiskVolume(Optional ByVal strDiskName = "C") As String Dim TempStr1 As String * 256, TempStr2 As String * 256 Dim TempLon1 As Long, TempLon2 As Long, GetVal As Long Dim tmpVol As String Call GetVolumeInformation(strDiskName & ":\", TempStr1, 256, GetVal, TempLon1, TempLon2, TempStr2, 256) If GetVal = 0 Then tmpVol = "" Else tmpVol = Hex(GetVal) tmpVol = String(8 - Len(tmpVol), "0") & tmpVol tmpVol = Left(tmpVol, 4) & "-" & Right(tmpVol, 4) End If GetDiskVolume = tmpVol End Function '取得硬盘信息:型号/物理系列号(唯一) Function GetHardDiskInfo(Optional ByVal numDisk As eumDiskNo = hdPrimaryMaster, Optional ByVal numType As eumInfoType = hdOnlySN) As String If GetDiskInfo(numDisk) = 1 Then Dim pSerialNumber As String, pModelNumber As String pSerialNumber = StrConv(m_DiskInfo.sSerialNumber, vbUnicode) pModelNumber = StrConv(m_DiskInfo.sModelNumber, vbUnicode) Select Case numType Case hdOnlyModel '仅型号 GetHardDiskInfo = Trim(pModelNumber) Case hdOnlySN '仅系列号 GetHardDiskInfo = Trim(pSerialNumber) Case Else '型号,系列号 GetHardDiskInfo = Trim(pModelNumber) & "," & Trim(pSerialNumber) End Select End If End Function Private Function OpenSMART(ByVal nDrive As Byte) As Long Dim hSMARTIOCTL As Long Dim hd As String Dim VersionInfo As OSVERSIONINFO hSMARTIOCTL = INVALID_HANDLE_VALUE 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 Function 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 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 pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4) ' pSCIP.irDriveRegs.bCommandReg = bIDCmd pSCIP.bDriveNumber = bDriveNum pSCIP.cBufferSize = IDENTIFY_BUFFER_SIZE DoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, _ pSCIP, 32, _ pSCOP(0), 528, _ lpcbBytesReturned, 0)) End Function Private Function DoEnableSMART(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP As SENDCMDOUTPARAMS, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As Boolean 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 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 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
|