How to eject CD drive from a .vbs file or from PowerShell


Friends,
This time I have taken for you some coding concepts. Many times we find that we need to eject the CD drive but we couldn't because either the switch to open it has been broken or the system has been hanged. But here is a very easy trick to open CD drive just by a single click.

Trick-1 with .vbs


Open a notepad and paste the following code in it.
Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
    For i = 0 to colCDROMs.Count - 1
        colCDROMs.Item(i).Eject
    Next
End If
Save the file as .vbs extension.
Now double click the file to see what happens.

Trick-2 (For windows 7 only)


Just open Windows PowerShell (to open it you can type PowerShell in start menu).
Copy the following code.
param( [string] $help )

if ( $help -eq "" ) {
 $colCDROMs = ( new-object -COM WMPlayer.OCX.7 ).cdromCollection
 for ( $i = 0; $i -lt $colCDROMs.count ; $i++ ) 
        { 
          $colCDROMs.Item( $i ).eject( ) 
        }
}
Right click on the title bar at the top. Go to Edit->Paste
Now press enter to execute and see what happens.

(You will definitely like to see how to reveal the hidden files using command prompt)

Like this article ? Tell your friends.

Like our site ? Follow us now.

You can also subscribe to our Newsletter

comments powered by Disqus