Enables or disables the mechanism that ejects media, for those devices possessing that locking capability
#include <WinAPIFiles.au3>
_WinAPI_LockDevice ( $sDrive, $bLock )
$sDrive | The drive letter of the device to enable or disable, in the format D:, E:, etc. |
$bLock | Specifies whether the device should be disabled, valid values: True - The device is disabled. False - The device is enabled. |
Success: | True. |
Failure: | False and sets the @error flag to non-zero. |
This function is valid only for devices that support removable media.
Search IOCTL_STORAGE_MEDIA_REMOVAL in MSDN Library.
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Local $aDrive = DriveGetDrive('CDROM')
If IsArray($aDrive) Then
_WinAPI_LockDevice($aDrive[1], 1)
MsgBox($MB_SYSTEMMODAL, '', 'The drive (' & StringUpper($aDrive[1]) & ') is locked.')
_WinAPI_LockDevice($aDrive[1], 0)
MsgBox($MB_SYSTEMMODAL, '', 'The drive (' & StringUpper($aDrive[1]) & ') is unlocked.')
EndIf