Const $DISK_PATH = "\\.\H:"
Const $IOCTL_DISK_IS_WRITABLE = 0x70024
Const $GENERIC_READ = 0x80000000
Const $ERROR_WRITE_PROTECT = 19
Local $hDiskDrive, $iStatus
$hDiskDrive = DllCall("Kernel32.dll", "handle", "CreateFileW", "wstr", $DISK_PATH, "dword", $GENERIC_READ, "long", 3, "ptr", 0, "dword", 3, "long", 0, "handle", 0)
$hDiskDrive = $hDiskDrive[0]
$iStatus = DllCall("Kernel32.dll", "bool", "DeviceIoControl", "handle", $hDiskDrive, "dword", $IOCTL_DISK_IS_WRITABLE, "ptr", 0, "long", 0, "ptr", 0, "long", 0, "long*", 0, "ptr", 0)
If $iStatus[0] Then
MsgBox(48, "OK", StringFormat("'%s' is writable.", $DISK_PATH))
Else
$iStatus = DllCall("Kernel32.dll", "long", "GetLastError")
If $iStatus[0] = $ERROR_WRITE_PROTECT Then
MsgBox(48, "OK", StringFormat("'%s' is read-only.", $DISK_PATH))
Else
MsgBox(48, "Error", StringFormat("Cannot determine, error code: %d", $iStatus[0]))
EndIf
EndIf
DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hDiskDrive)
|