Aşağıdaki kodları bir modül dosyasına kopyalayınız.
—————————————————
‘****************************************************************************************************
‘Information:
‘————
‘Here is a code to get low level HDD info. Tested on Win95(OSR2)/Win98/WinNT/Win2000.
‘At least Primary master HDD info is available
‘(including HDD serial number, physical geometry and miscelaneous HDD parameters).
‘
‘For Win95/Win98 :
‘—————–
‘For some reasons MS didn’t include smartvsd.vxd driver in some versions.
‘It may present, may not. Check your %windows%systemiosubsys folder for smartvsd.vxd.
‘If this file not present in this folder, just copy it into folder and reboot machine.
‘****************************************************************************************************
Option Explicit
‘Definitions
‘Max number of drives assuming primary/secondary, master/slave topology
Public Const MAX_IDE_DRIVES = 4
Public Const READ_ATTRIBUTE_BUFFER_SIZE = 512
Public Const IDENTIFY_BUFFER_SIZE = 512
Public Const READ_THRESHOLD_BUFFER_SIZE = 512
Public Const OUTPUT_DATA_SIZE = IDENTIFY_BUFFER_SIZE + 16
‘IOCTL commands
Public Const DFP_GET_VERSION = &H74080
Public Const DFP_SEND_DRIVE_COMMAND = &H7C084
Public Const DFP_RECEIVE_DRIVE_DATA = &H7C088
‘GETVERSIONOUTPARAMS contains the data returned from the Get Driver Version function.
Public Type GETVERSIONOUTPARAMS
bytVersion As Byte ’Binary driver version.
bytRevision As Byte ’Binary driver revision.
bytReserved As Byte ’Not used.
bytIDEDeviceMap As Byte ’Bit map of IDE devices.
lngCapabilities As Long ’Bit mask of driver capabilities.
lngReserved(3) As Long ’For future use.
End Type
‘Bits returned in the lngCapabilities member of GETVERSIONOUTPARAMS
Public Const CAP_IDE_ID_FUNCTION = 1 ’ATA ID command supported
Public Const CAP_IDE_ATAPI_ID = 2 ‘ATAPI ID command supported
Public Const CAP_IDE_EXECUTE_SMART_FUNCTION = 4 ‘SMART commannds supported
‘IDE registers
Public Type IDEREGS
bytFeaturesReg As Byte ’Used for specifying SMART “commands”.
bytSectorCountReg As Byte ’IDE sector count register
bytSectorNumberReg As Byte ’IDE sector number register
bytCylLowReg As Byte ’IDE low order cylinder value
bytCylHighReg As Byte ’IDE high order cylinder value
bytDriveHeadReg As Byte ’IDE drive/head register
bytCommandReg As Byte ’Actual IDE command.
bytReserved As Byte ’reserved for future use. Must be zero.
End Type
‘SENDCMDINPARAMS contains the input parameters for the Send Command to Drive function.
Public Type SENDCMDINPARAMS
lngBufferSize As Long ‘Buffer size in bytes
irDriveRegs As IDEREGS ’Structure with drive register values.
bytDriveNumber As Byte ‘Physical drive number to send command to (0,1,2,3).
bytReserved(2) As Byte ‘Bytes reserved
lngReserved(3) As Long ‘DWORDS reserved
bytBuffer() As Byte ’Input buffer.
End Type
‘Valid values for the bytCommandReg member of IDEREGS.
Public Const IDE_ATAPI_ID = &HA1 ’Returns ID sector for ATAPI.
Public Const IDE_ID_FUNCTION = &HEC ‘Returns ID sector for ATA.
Public Const IDE_EXECUTE_SMART_FUNCTION = &HB0 ’Performs SMART cmd.
’Requires valid bytFeaturesReg, bytCylLowReg and bytCylHighReg
‘Cylinder register values required when issuing SMART command
Public Const SMART_CYL_LOW = &H4F
Public Const SMART_CYL_HI = &HC2
‘Status returned from driver
Public Type DRIVERSTATUS
bytDriverError As Byte ’Error code from driver, or 0 if no error.
bytIDEStatus As Byte ’Contents of IDE Error register.
‘Only valid when bytDriverError is SMART_IDE_ERROR.
bytReserved(1) As Byte
lngReserved(1) As Long
End Type
‘bytDriverError values
Public Enum DRIVER_ERRORS
SMART_NO_ERROR = 0 ‘No error
SMART_IDE_ERROR = 1 ’Error from IDE controller
SMART_INVALID_FLAG = 2 ‘Invalid command flag
SMART_INVALID_COMMAND = 3 ’Invalid command byte
SMART_INVALID_BUFFER = 4 ‘Bad buffer (null, invalid addr..)
SMART_INVALID_DRIVE = 5 ’Drive number not valid
SMART_INVALID_IOCTL = 6 ’Invalid IOCTL
SMART_ERROR_NO_MEM = 7 ‘Could not lock user’s buffer
SMART_INVALID_REGISTER = 8 ‘Some IDE Register not valid
SMART_NOT_SUPPORTED = 9 ’Invalid cmd flag set
SMART_NO_IDE_DEVICE = 10 ‘Cmd issued to device not present although drive number is valid
’11-255 reserved
End Enum
‘The following struct defines the interesting part of the IDENTIFY buffer:
Public Type IDSECTOR
intGenConfig As Integer
intNumCyls As Integer
intReserved As Integer
intNumlngHeads As Integer
intlngBytesPerTrack As Integer
intlngBytesPerSector As Integer
intSectorsPerTrack As Integer
intVendorUnique(2) As Integer
bytstrSerialNumber(19) As Byte
intBufferType As Integer
intBufferSize As Integer
intECCSize As Integer
bytstrFirmWareRev(7) As Byte
bytstrModelNumber(39) As Byte
intMoreVendorUnique As Integer
intDoubleWordIO As Integer
intCapabilities As Integer
intReserved1 As Integer
intPIOTiming As Integer
intDMATiming As Integer
intBS As Integer
intNumCurrentCyls As Integer
intNumCurrentlngHeads As Integer
intNumCurrentSectorsPerTrack As Integer
lngCurrentSectorCapacity As Long
intMultSectorStuff As Integer
lngTotalAddressableSectors As Long
intSingleWordDMA As Integer
intMultiWordDMA As Integer
bytReserved(127) As Byte
End Type
‘Structure returned by SMART IOCTL for several commands
Public Type SENDCMDOUTPARAMS
lngBufferSize As Long ‘Size of bytBuffer in bytes (IDENTIFY_BUFFER_SIZE in our case)
DRIVERSTATUS As DRIVERSTATUS ‘Driver status structure.
bytBuffer() As Byte ‘Buffer of arbitrary length in which to store the data read from the drive.
End Type
‘Feature register defines for SMART “sub commands”
Public Const SMART_READ_ATTRIBUTE_VALUES = &HD0
Public Const SMART_READ_ATTRIBUTE_THRESHOLDS = &HD1
Public Const SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE = &HD2
Public Const SMART_SAVE_ATTRIBUTE_VALUES = &HD3
Public Const SMART_EXECUTE_OFFLINE_IMMEDIATE = &HD4
‘Vendor specific commands:
Public Const SMART_ENABLE_SMART_OPERATIONS = &HD8
Public Const SMART_DISABLE_SMART_OPERATIONS = &HD9
Public Const SMART_RETURN_SMART_STATUS = &HDA
‘The following structure defines the structure of a Drive Attribute
Public Const NUM_ATTRIBUTE_STRUCTS = 30
Public Type DRIVEATTRIBUTE
bytAttrID As Byte ’Identifies which attribute
intsfStatusFlags As Integer ’Integer ‘ see bit definitions below
bytbytAttrValue As Byte ‘Current normalized value
bytbytWorstValue As Byte ’How bad has it ever been?
bytRawValue(5) As Byte ‘Un-normalized value
bytReserved As Byte ’…
End Type
‘Status Flags Values
Public Enum STATUS_FLAGS
PRE_FAILURE_WARRANTY = &H1
ON_LINE_COLLECTION = &H2
PERFORMANCE_ATTRIBUTE = &H4
ERROR_RATE_ATTRIBUTE = &H8
EVENT_COUNT_ATTRIBUTE = &H10
SELF_PRESERVING_ATTRIBUTE = &H20
End Enum
‘The following structure defines the structure of a Warranty Threshold Obsoleted in ATA4!
Public Type ATTRTHRESHOLD
bytAttrID As Byte ‘Identifies which attribute
bytWarrantyThreshold As Byte ’Triggering value
bytReserved(9) As Byte ’…
End Type
Continue Reading »