Casting ssfDRIVES works for me :
objShell.NameSpace(CType(ssfDRIVES, Object)).ParseName(UsbDrive).InvokeVerb("Eject")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Form has a ComboBox and a button.
Imports System.IO
Imports System.Management
Imports Shell32
Public Class Form1
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
'Dim driveArray() As String = System.IO.Directory.GetLogicalDrives
Dim Drives As DriveInfo() = System.IO.DriveInfo.GetDrives()
For Each d As DriveInfo In Drives
If d.DriveType = DriveType.Removable Then
CBDrives.Items.Add(d.Name)
End If
Next
End Sub
Private Sub Eject(DriveLetter As String)
Dim UsbDrive As String = DriveLetter
Dim ssfDRIVES As Integer = 17
Dim objShell As Object = CreateObject("shell.application")
objShell.NameSpace(ssfDRIVES).ParseName(UsbDrive).InvokeVerb("Eject") '
Exception = 'Object variable or With block variable not set
'powershell(this works)
'$driveEject = New-Object -comObject Shell.Application
'$driveEject.Namespace(17).ParseName("H:").InvokeVerb("Eject")
End Sub
Private Sub BtnEj_Click(sender As Object, e As EventArgs) Handles BtnEj.Click
Eject(CBDrives.Text)
End Sub
End Class
Casting ssfDRIVES works for me :
objShell.NameSpace(CType(ssfDRIVES, Object)).ParseName(UsbDrive).InvokeVerb("Eject")