这里有段代码, 不知道有没有帮助...<br><br>unit TapeCheck;<br><br>{==============================================================================}<br>{ Interface Section }<br>{==============================================================================}<br><br>interface<br><br>uses SysUtils, Classes, Dialogs, stdctrls, Gauges, messages, Windows, Forms,<br>ComCtrls ;<br><br>TYPE<br> TTapeRecord = record<br> WriteProtect : String;<br> BlockSize : String;<br> PartitionCount : String;<br> CLP : String;<br> CHP : String;<br> CQP : String;<br> RLP : String;<br> RHP : String;<br> RQP : String;<br> end;<br><br>TDriveRecord = record<br> ECC : String;<br> Compression : String;<br> DataPadding : String;<br> ReportSetMarks : String;<br> DefaultBlockSize : String;<br> MaximumBlockSize : String;<br> MinimumBlockSize : String;<br> MaximumPartitionCount : String;<br> FeaturesLow : String;<br> FeaturesHigh : String;<br> EOTWarningZoneSize : String;<br> end;<br><br><br><br> TTapeCheck = CLASS(TObject)<br><br><br>private<br><br><br>PUBLIC<br> TapeRecord : TTapeRecord;<br> DriveRecord : TdriveRecord;<br> Constructor create;<br> function uCheckStatus : string;<br> Function TapeStatus : string;<br> Function GetDriveStatus: string;<br> function uRewind : String;<br> function uErase : String;<br> function OpenDrive : THandle;<br> Procedure CloseDrive(TapeHandle : THandle; ms : dword);<br> Function ErrorCodes( eword : dword) : string;<br> procedure SpoolMessages;<br>end; { Class TtapeCheck }<br><br><br><br><br>{------------------------------------------------------------------------------}<br>{ TAPE_GET_DRIVE_PARAMETERS has not been defined in the VCL as of Delphi 4 }<br>{ 5.37. If future releases declare it in Windows.pas}<br>{ this record could conflict and cause unknown }<br>{ errors which should go away if you remove this }<br>{ record. }<br>{------------------------------------------------------------------------------}<br><br>TAPE_GET_DRIVE_PARAMETERS = record<br> ECC : boolean;<br> Compression : boolean;<br> DataPadding : boolean;<br> ReportSetMarks : Boolean;<br> DefaultBlockSize : DWORD;<br> MaximumBlockSize : DWORD;<br> MinimumBlockSize : DWORD;<br> MaximumPartitionCount : DWORD;<br> FeaturesLow : DWORD;<br> FeaturesHigh : DWORD;<br> EOTWarningZoneSize : DWORD;<br> end;<br><br>{------------------------------------------------------------------------------}<br>{ TAPE_GET_MEDIA_PARAMETERS has not been defined in the VCL as of Delphi 4 }<br>{ 5.37. If future releases declare it in Windows.pas}<br>{ this record could conflict and cause unknown }<br>{ errors which should go away if you remove this }<br>{ record. }<br>{------------------------------------------------------------------------------}<br><br> TAPE_GET_MEDIA_PARAMETERS = record<br> Capacity : LARGE_INTEGER;<br> Remaining : LARGE_INTEGER;<br> BlockSize : DWORD;<br> PartitionCount : DWORD;<br> WriteProtected : BOOLEAN;<br> end;<br><br>{==============================================================================}<br>{ Implementation }<br>{==============================================================================}<br><br>implementation<br><br>{------------------------------------------------------------------------------}<br>{ Constructor create - Create an instance of TtapeCheck }<br>{------------------------------------------------------------------------------}<br>Constructor TtapeCheck.create;<br>Begin<br>end;<br><br>{------------------------------------------------------------------------------}<br>{ function uCheckStatus - Tries to open a Tape device and returns an error as }<br>{ string if any problem exists }<br>{------------------------------------------------------------------------------}<br><br>function TtapeCheck.uCheckStatus : string;<br>var<br> TapeHandle : THandle;<br> eword : dword;<br> ErrorMsg : string;<br>begin<br> result := '';<br> { open the Tape drive }<br> TapeHandle := OpenDrive;<br><br> if Tapehandle = 0 then<br> begin<br> result := 'Unable to find tape drive on system or tape drive in use';<br> Exit;<br> end;<br><br> eword := GetTapeStatus(TapeHandle);<br> SpoolMessages;<br><br><br> ErrorMsg := ErrorCodes(eword);<br> if Length(ErrorMsg) > 0 then<br> Result := ErrorMsg;<br><br> CloseDrive(TapeHandle,10000);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ TapeStatus - Function retrieves information that describe tape in the drive }<br>{------------------------------------------------------------------------------}<br>FUNCTION TtapeCheck.TapeStatus : string;<br>var<br> eword : dword;<br> dwsize : cardinal;<br> TapeHandle : THandle;<br> TapeInfo : TAPE_GET_MEDIA_PARAMETERS;<br> ErrorMsg : string;<br>begin<br>TapeHandle := OpenDrive;<br><br> if Tapehandle = 0 then<br> begin<br> result := 'Unable to find tape drive on system or tape drive in use';<br> Exit;<br> end;<br><br><br> eword := GetTapeParameters(TapeHandle,GET_TAPE_MEDIA_INFORMATION,<br> dwsize,@TapeInfo);<br><br> SpoolMessages;<br><br> if TapeInfo.WriteProtected then<br> TapeRecord.WriteProtect := 'Write Protected = TRUE '<br> else<br> TapeRecord.WriteProtect := 'Write Protected = FALSE ';<br><br><br><br> TapeRecord.BlockSize := 'Block Size '<br> + IntToStr(TapeInfo.BlockSize);<br><br> TapeRecord.PartitionCount := 'Partition Count '<br> + IntToStr(TapeInfo.PartitionCount);<br><br> TapeRecord.CLP := 'Capacity Low Part '<br> + IntToStr(TapeInfo.Capacity.Lowpart);<br><br> TapeRecord.CHP := 'Capacity High Part '<br> + IntToStr(TapeInfo.Capacity.Highpart);<br><br> TapeRecord.CQP := 'Capacity Quad Part '<br> + IntToStr(TapeInfo.Capacity.Quadpart);<br><br> TapeRecord.RLP := 'Remaining Low Part '<br> + IntToStr(TapeInfo.Remaining.Lowpart);<br><br> TapeRecord.RHP := 'Remaining High Part '<br> + IntToStr(TapeInfo.Remaining.Highpart);<br><br> TapeRecord.RQP := 'Remaining Quad Part '<br> + IntToStr(TapeInfo.Remaining.Quadpart);<br><br> ErrorCodes(eword);<br> if Length(ErrorMsg) > 0 then<br> Result := ErrorMsg;<br><br> CloseDrive(TapeHandle,1);<br><br>end;<br><br><br>{------------------------------------------------------------------------------}<br>{ GetDriveStatus - Function retrieves information that describe tape drive }<br>{------------------------------------------------------------------------------}<br>function TtapeCheck.GetDriveStatus : string;<br>var<br> eword : dword;<br> dwsize : cardinal;<br> TapeHandle : THandle;<br> TapeInfo : TAPE_GET_DRIVE_PARAMETERS;<br> ErrorMsg : string;<br>begin<br> TapeHandle := OpenDrive;<br><br> if Tapehandle = 0 then<br> Exit;<br><br><br> eword := GetTapeParameters(TapeHandle,GET_TAPE_DRIVE_INFORMATION,<br> dwsize,@TapeInfo);<br> SpoolMessages;<br><br> if TapeInfo.ECC then<br> DriveRecord.ECC := 'Error Control = TRUE '<br> else<br> DriveRecord.ECC := 'Error Control = FALSE ';<br><br> if TapeInfo.Compression then<br> DriveRecord.Compression := 'Compression = TRUE '<br> else<br> DriveRecord.Compression :='Compression = FALSE ';<br><br> if TapeInfo.DataPadding then<br> DriveRecord.DataPadding := 'Data Padding = TRUE '<br> else<br> DriveRecord.DataPadding := 'Data Padding = FALSE ';<br><br> if TapeInfo.ReportSetMarks then<br> DriveRecord.ReportSetMarks := 'Report Set Marks = TRUE '<br> else<br> DriveRecord.ReportSetMarks := 'Report Set Marks = FALSE ';<br><br> DriveRecord.DefaultBlockSize := 'Default Block Size ' +<br> IntToStr(TapeInfo.DefaultBlockSize);<br><br><br> DriveRecord.MaximumBlockSize := 'Maximum Block Size '<br> + IntToStr(TapeInfo.MaxiMumBlockSize);<br><br> DriveRecord.MinimumBlockSize := 'Minimum Block Size '<br> + IntToStr(TapeInfo.MinimumBlockSize);<br><br> DriveRecord.MaximumPartitionCount := 'Maximum Partition Count ' +<br> IntToStr(TapeInfo.MaxiMumPartitionCount);<br><br> DriveRecord.FeaturesLow :='Features Low ' +<br> IntToStr(TapeInfo.FeaturesLow);<br><br> DriveRecord.FeaturesHigh := 'Features High ' +<br> IntToStr(TapeInfo.FeaturesHigh);<br><br> DriveRecord.EOTWarningZoneSize := 'EOT Warning Zone Size ' +<br> IntToStr(TapeInfo.EOTWarningZoneSize);<br><br><br> ErrorCodes(eword);<br> if Length(ErrorMsg) > 0 then<br> Result := ErrorMsg;<br><br> CloseDrive(TapeHandle,1);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ uRewind - Rewinds the current tape in the machine. Returns any error as a }<br>{ String. }<br>{------------------------------------------------------------------------------}<br>function TtapeCheck.uRewind : string;<br>var<br> TapeHandle : THandle;<br> eword : dword;<br> TAPE_REWIND : LongInt;<br> ErrorMsg : string;<br>begin<br> result := '';<br> { open the existing file for reading }<br> TapeHandle := OpenDrive;<br><br> if Tapehandle = 0 then<br> begin<br> result := 'Unable to find tape drive on system or tape drive in use';<br> Exit;<br> end;<br><br> TAPE_REWIND := 0;<br><br> eword := SetTapePosition(TapeHandle,TAPE_REWIND,0,0,0,TRUE);<br> SpoolMessages;<br><br><br> CloseDrive(TapeHandle,10000);<br><br> ErrorMsg := ErrorCodes(eword);<br> if Length(ErrorMsg) > 0 then<br> Result := ErrorMsg;<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ uErase - Will erase tape in the drive. Returns any error as a string }<br>{------------------------------------------------------------------------------}<br>Function TtapeCheck.uErase : string;<br>var<br> TapeHandle : THandle;<br> eword : dword;<br> ErrorMsg : String;<br>begin<br> result := '';<br> { open the tape drive }<br><br> TapeHandle := OpenDrive;<br><br> if Tapehandle = 0 then<br> begin<br> result := 'Unable to find tape drive on system or tape drive in use';<br> Exit;<br> end;<br><br> eword := EraseTape(TapeHandle,0,TRUE);<br> SpoolMessages;<br><br> ErrorMsg := ErrorCodes(eword);<br> if Length(ErrorMsg) > 0 then<br> Result := ErrorMsg;<br><br> CloseDrive(TapeHandle,10000);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ OpenDrive - Opens the default tape drive on the system. Returns the handle }<br>{ of the tape device. }<br>{------------------------------------------------------------------------------}<br><br>function TtapeCheck.OpenDrive : THandle;<br>var<br> TapeHandle : THandle;<br> Security : TSecurityAttributes;<br>begin<br> Security.nLength := SizeOf(TSecurityAttributes);<br> Security.bInheritHandle := FALSE;<br> Security.lpSecurityDescriptor := nil;<br> TapeHandle := CreateFile('/.TAPE0', GENERIC_READ OR GENERIC_WRITE,<br> FILE_SHARE_READ OR FILE_SHARE_WRITE,<br> @SECURITY,<br> OPEN_EXISTING, 0, 0);<br><br> { indicate an error if the tape drive does not exist }<br> if TapeHandle=INVALID_HANDLE_VALUE then<br> result := 0<br> else<br> result := tapeHandle;<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ CloseDrive - procedure to close a tape handle }<br>{------------------------------------------------------------------------------}<br><br>Procedure TtapeCheck.CloseDrive(TapeHandle : THandle; ms : dword);<br>begin<br> sleep(ms); { allow time for tape drive to reset before close }<br> closehandle(TapeHandle);<br>end;<br><br><br>{------------------------------------------------------------------------------}<br>{ Function ErrorCodes - Converts error code value to a description and returns }<br>{ it as a string. }<br>{------------------------------------------------------------------------------}<br><br>Function TtapeCheck.ErrorCodes( eword : dword) : string;<br>begin<br> if eword = ERROR_MEDIA_CHANGED then eword := 0;<br> if eword = ERROR_BUS_RESET then eword := 0;<br> if eword = 0 then<br> result := '';<br><br> if eword = 1 then<br> result := 'This Tape drive does not support this function';<br><br> if eword = ERROR_FILE_NOT_FOUND then { 2 }<br> result := 'The system cannot find the file specified. ';<br><br> if eword = ERROR_PATH_NOT_FOUND then { 3 }<br> result := 'The system cannot find the path specified. ';<br><br> if eword = ERROR_TOO_MANY_OPEN_FILES then { 4 }<br> result := 'The system cannot open the file. ';<br><br> if eword = ERROR_ACCESS_DENIED then { 5 }<br> result := 'Access is denied. ';<br><br> if eword = ERROR_INVALID_HANDLE then { 6 }<br> result := 'The handle is invalid. ';<br><br> if eword = ERROR_ARENA_TRASHED then { 7 }<br> result := 'The storage control blocks were destroyed. ';<br><br> if eword = ERROR_NOT_ENOUGH_MEMORY then { 8 }<br> result := 'Not enough storage is available to process this command. ';<br><br> if eword = ERROR_INVALID_BLOCK then { 9 }<br> result := 'The storage control block address is invalid. ';<br><br> if eword = ERROR_BAD_ENVIRONMENT then { 10 }<br> result := 'The environment is incorrect. ';<br><br> if eword = ERROR_BAD_FORMAT then { 11 }<br> result := 'An attempt was made to load a program with an incorrect format.';<br><br> if eword = ERROR_INVALID_ACCESS then { 12 }<br> result := 'The access code is invalid. ';<br><br> if eword = ERROR_INVALID_DATA then { 13 }<br> result := 'The data is invalid. ';<br><br> if eword = ERROR_OUTOFMEMORY then { 14 }<br> result := 'Not enough storage is available to complete the operation. ';<br><br> if eword = ERROR_INVALID_DRIVE then { 15 }<br> result := 'The system cannot find the drive specified. ';<br><br> if eword = ERROR_CURRENT_DIRECTORY then { 16 }<br> result := 'The directory cannot be removed. ';<br><br> if eword = ERROR_NOT_SAME_DEVICE then { 17 }<br> result := 'The system cannot move the file to a different disk drive. ';<br><br> if eword = ERROR_NO_MORE_FILES then { 18 }<br> result := 'There are no more files. ';<br><br> if eword = ERROR_WRITE_PROTECT then { 19 }<br> result := 'Error, The write protect is set ';<br><br> if eword = ERROR_BAD_UNIT then { 20 }<br> result := 'Error, The system cannot find the device ';<br><br> if eword = ERROR_NOT_READY then { 21 }<br> result := 'The device is not ready ';<br><br> if eword = ERROR_BAD_COMMAND then { 22 }<br> result := 'The device does not recognize the command. ';<br><br> if eword = ERROR_CRC then { 23 }<br> result := 'Data error (cyclic redundancy check). ';<br><br> if eword = ERROR_BAD_LENGTH then{ 24 }<br> result := 'Incorrect command length from program ';<br><br> if eword = ERROR_SEEK then { 25 }<br> result := 'The drive cannot locate a specfic area or track on the disk ';<br><br> if eword = ERROR_NOT_DOS_DISK then { 26 }<br> result := 'The specified disk or diskette cannot be accessed. ';<br><br> if eword = ERROR_SECTOR_NOT_FOUND then { 27 }<br> result := 'The drive cannot find the sector requested. ';<br><br> if eword = ERROR_OUT_OF_PAPER then { 28 }<br> result := 'The Printer is out of paper. ';<br><br> if eword = ERROR_WRITE_FAULT then { 29 }<br> result := 'The system cannot read from the specified device. ';<br><br> if eword = ERROR_READ_FAULT then { 30 }<br> result := 'The system cannot read from the specified device. ';<br><br> if eword = ERROR_GEN_FAILURE then { 31 }<br> result := 'A device attached to the system is not functioning. ';<br><br> if eword = ERROR_SHARING_VIOLATION then { 32 }<br> result := 'The file is being using by another process. ';<br><br> if eword = ERROR_LOCK_VIOLATION then { 33 }<br> result := 'Another process has locked the file. ';<br><br> if eword = ERROR_WRONG_DISK then { 34 }<br> result := 'The wrong diskette is in the drive. ';<br><br> if eword = ERROR_SHARING_BUFFER_EXCEEDED then{ 36 }<br> result := 'Too many files opened for sharing. ';<br><br> if eword = ERROR_HANDLE_EOF then { 38 }<br> result := 'Reached end of file ';<br><br> if eword = ERROR_HANDLE_DISK_FULL then { 39 }<br> result := 'The disk is full ';<br><br> if eword = ERROR_NOT_SUPPORTED then { 50 }<br> result := 'The network request is not supported. ';<br><br> if eword = ERROR_MORE_DATA then { 234 }<br> result := 'More data is available ';<br><br> if eword = ERROR_END_OF_MEDIA then { 1100 }<br> result := 'Error, End of media ';<br><br> if eword = ERROR_FILEMARK_DETECTED then { 1101 }<br> result := 'Error, Filemark detected ';<br><br> if eword = ERROR_BEGINNING_OF_MEDIA then { 1102 }<br> result := 'Error, Cannot access data before medium marker ';<br><br> if eword = ERROR_SETMARK_DETECTED then { 1103 }<br> result := 'Error, A setmark was reached ';<br><br> if eword = ERROR_NO_DATA_DETECTED then { 1104 }<br> result := 'Error, Eof of data marker reached ';<br><br> if eword = ERROR_PARTITION_FAILURE then { 1105 }<br> result := 'Error, The tape could not be partitioned ';<br><br> if eword = ERROR_INVALID_BLOCK_LENGTH then { 1106 }<br> result := 'Error, The Block size is incorrect ';<br><br> if eword = ERROR_DEVICE_NOT_PARTITIONED then { 1107 }<br> result := 'Error, Partition information not found ';<br><br> if eword = ERROR_UNABLE_TO_LOCK_MEDIA then { 1108 }<br> result := 'Error, An attempt to lock the ejection mechanism failed ';<br><br> if eword = ERROR_UNABLE_TO_UNLOAD_MEDIA then { 1109 }<br> result := 'Error, An attempt to unload the media failed ';<br><br> if eword = ERROR_MEDIA_CHANGED then { 1110 }<br> result := 'Error, The tape in the drive has been replaced. ' +<br> ' This tape drive may be type QIC which is not supported. ';<br><br> if eword = ERROR_BUS_RESET then { 1111 }<br> result := 'Error, A reset condition was detected on the bus ';<br><br> if eword = ERROR_NO_MEDIA_IN_DRIVE then { 1112 }<br> result := 'There is no media in the drive ';<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ SpoolMessages - checks a thread message queue for a message and places }<br>{ the message (if any) in the specified structure. }<br>{ Allows screen updates after a task switch and back }<br>{------------------------------------------------------------------------------}<br><br>procedure TtapeCheck.SpoolMessages;<br>var<br> Msg : TMsg;<br>begin<br> while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do<br> begin<br> TranslateMessage(Msg);<br> DispatchMessage(Msg);<br> end<br><br>end;<br><br> { its the end of the world as we know it. }<br>end.