1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Public Sub EjectUsb()
Dim fso As Object, USBDrive As Object, myShell As Object, myDrive As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set myShell = CreateObject("Shell.Application")
For Each myDrive In fso.Drives
If myDrive.DriveType = 1 And myDrive.IsReady = True Then 'removeable and mounted
' If myDrive.VolumeName = strVolumeName Then
Set USBDrive = myShell.Namespace(17).Parsename(myDrive.Path)
If USBDrive.Type = "Lecteur USB" Then ' Check it really is a USB drive
USBDrive.InvokeVerb "Eject"
End If
'End If
End If
Next
End Sub |
Partager