Determines whether a disk is writable
#include <WinAPIFiles.au3>
_WinAPI_IsWritable ( $sDrive )
$sDrive | The drive letter of the disk to check, in the format D:, E:, etc. |
Success: | True - The disk is writable. False - Otherwise. |
Failure: | Sets the @error flag to non-zero, @extended is set to last system error code. |
The last error code = 41 means that the device is not ready, no media mounted.
Search IOCTL_DISK_IS_WRITABLE in MSDN Library.
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>
Local $aDrive = DriveGetDrive('ALL')
If IsArray($aDrive) Then
Local $sText
For $i = 1 To $aDrive[0]
If _WinAPI_IsWritable($aDrive[$i]) Then
$sText = 'Writable'
Else
If @error Then
$sText = 'No media'
If @extended Then $sText &= ' ( @error=' & @error & ' LastError=' & _WinAPI_GetLastErrorMessage() & ')'
Else
$sText = 'Not writable'
EndIf
EndIf
ConsoleWrite(StringUpper($aDrive[$i]) & ' => ' & $sText & @CRLF)
Next
EndIf