Ejects/retracts the tray in a CD or DVD drive, or sets a drive's volume label.

Drive, Sub-command [, Drive , Value]


The sub-command, drive, and value parameters are dependent upon each other and their usage is described below.

Label, Drive [, NewLabel]: Changes Drive's volume label to be NewLabel (if NewLabel is omitted, the drive will have no label). Drive is the drive letter followed by a colon and an optional backslash (might also work on UNCs and mapped drives). For example: Drive, Label, C:, Seagate200

To retrieve the current label, follow this example: DriveGet, OutputVar, Label, C:

Lock, Drive
: Prevents a drive's eject feature from working. For example: "Drive, Lock, D:". Most drives cannot be "locked open". However, locking the drive while it is open will probably result in it becoming locked the moment it is closed. This command has no effect on drives that do not support locking (such as most read-only drives), nor is it likely to work on non-IDE drives on Windows 95/98/Me. If a drive is locked by a script and that script exits, the drive will stay locked until another script or program unlocks it, or the system is restarted. If the specified drive does not exist or does not support the locking feature, ErrorLevel is set to 1. Otherwise, it is set to 0.

Unlock, Drive: Reverses the above. On Window NT/2000/XP or later, Unlock needs to be executed multiple times if the drive was locked multiple times (at least for some drives). For example, if "Drive, Lock, D:" was executed three times, three executions of "Drive, Unlock, D:" might be needed to unlock it. Because of this and the fact that there is no way to determine whether a drive is currently locked, it is often useful to keep track of its lock-state in a variable.

Eject [, Drive, 1]
: Ejects or retracts the tray of a CD or DVD drive (if Drive is omitted, the default CD/DVD drive will be used). To eject the tray, omit the last parameter. To retract/close the tray, specify 1 for the last parameter. Example for retraction: Drive, Eject, D:, 1

If the tray is already in the correct state (open or closed), ErrorLevel is set to 0 (i.e. "no error"). This command will probably not work on a network drive or non-CD/DVD drive; if it fails in such cases or for any other reason, ErrorLevel is set to 1.

It may be possible to detect the previous tray state by measuring the time the command takes to complete. For example, the following hotkey toggles the tray to the opposite state (open or closed):

Drive, Eject
; If the command completed quickly, the tray was probably already ejected.
; In that case, retract it:
if A_TimeSinceThisHotkey < 1000 ; Adjust this time if needed.
     Drive, Eject,, 1

This command waits for the ejection or retraction to complete before allowing the script to continue.

To determine the media status of a CD or DVD drive (playing, stopped, open, etc.), see DriveGet.



ErrorLevel is set to 1 of there was a problem or 0 otherwise.






DriveGet, DriveSpaceFree



Drive, Label, D:, BackupDrive

Drive, Eject,, 1 ; Retract (close) the tray of the default CD or DVD drive.