Public Sub EjectMedia(Drive As String)
Dim SecAttr As SECURITY_ATTRIBUTES
Dim ErrorResult
Dim hDevice As Long, Regs As Registers, RB As Long
hDevice = CreateFile("\\.\vwin32", 0, 0, SecAttr, 0, _
FILE_FLAG_DELETE_ON_CLOSE, 0)
If hDevice = -1 Then
ErrorResult = -1
Exit Sub
End If
With Regs
.RegAX = &H220D
.RegBX = Asc(Left(Drive, 1)) - 64
.RegCX = &H849
End With
ErrorResult = DeviceIoControl(hDevice, _
VWin32_DIOC_DOS_IOCTL, Regs, Len(Regs), Regs, _
Len(Regs), RB, 0)
ErrorResult = CloseHandle(hDevice)
End Sub
|