Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Batch file for ejecting media

  • This topic is locked This topic is locked



    New Member

  • Member
  • Pip
  • 1 posts
I currently have a batch file that will run the Safely Remove Hardware function (the same thing as double clicking on the safely remove hardware button in the system tray).

What I would really like, however, is for the batch file to actually go ahead and eject a specific media. Since my external hard drives always have the same drive letters, I feel like this should be possible.

Here's the text of the current batch file I'm using in case it helps. By the way, I know nothing about any of this programming.


echo off
echo Starting Safely Remove
%windir%\system32\RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll

  • 0




    Tech Staff

  • Technician
  • 1,323 posts
Welcome to Geeks to Go!

If you are trying to eject media from the your CD-ROM, you can use a VBS file for this. Save the following code as eject.vbs and then just run it using cscript.exe eject.vbs (or just double-click it if you want to test it).

Opening a CD drive:
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
		For i = 0 to colCDROMs.Count - 1
		Next ' cdrom
End If

If this isn't what you're looking for, please let me know.

  • 0



    New Member

  • Member
  • Pip
  • 8 posts
Mmmm sounds like it's not really "eject" but you want your USB devices "safely removed" automatically rather than having to do it yourself.

Here's a link that seems to have the information you need to get started:

  • 0



    Mechanised Mod

  • Moderator
  • 24,081 posts

Redundant thread closed to prevent any further spam posts.

  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP