How to tell if an optical drive has ejected

655 Views Asked by At

I am trying to eject an optical disc on a Windows PC connected to a robotic disc changer. I have the following powershell script which works most of the time:

$path=$args[0]
$sh = New-Object -Comobject "Shell.Application"
$sh.Namespace(17).Items() | 
    Where-Object { $_.Type -eq "Removable Disc" } |
    foreach { 
        if($_.Path -eq $path) { $_.InvokeVerb("Eject") }
    }

However, sometimes it doesn't work, presumably because Windows thinks the drive is still in use.

Is there any way I can get a response code from this to tell if it has successfully ejected the disc? Or otherwise tell if the disc is still mounted?

Alternatively, does anyone know a nice C++ way of doing it, which would be even better as I could avoid the need to call a separate script...

0

There are 0 best solutions below