Eject/Load DVDROM device from Command line in XP

S

SAI

I'd like to know if there are any specific commands to open/eject and load a
CD/DVD device from command prompt.

I dont want to use any utilities/downloads for the above purpose.
 
M

Mark L. Ferguson

Create this file in the C: root
(assumes CD drive letter is D: )
--EjectCD.vbs-- cut here--
Set objShell = CreateObject("Shell.Application")
Set MyComp=objShell.NameSpace(17)
Set CD=MyComp.ParseName("D:\")
Set Context=CD.Verbs
CD.InvokeVerb "E&ject"
--end file--cut---

Then, from the prompt

start C:\EjectCD.vbs
 
M

Mark L. Ferguson

Aside from a reboot, which would close the drawer, then you could do a

'CD.InvokeVerb "&Open" '

I know of no software interface to close it.
 
S

SAI

1. http://forums.pcpitstop.com/lofiversion/index.php/t143721.html

2. http://www.virtualplastic.net/msgboard/thread.php?forum=0&thread=158

3. This following one I downloaded from somewhere over the net, cant
remember where I got this code from??? Me think, its written in C++. Thought
it should shed some light on what I asked for, CLOSING the drive tray. FYI
------------------------------------------------------------------------------------------------
//
// AUTHOR
// N. Nielsen
//
// LICENSE
// This software is in the public domain.
//
// The software is provided "as is", without warranty of any kind,
// express or implied, including but not limited to the warranties
// of merchantability, fitness for a particular purpose, and
// noninfringement. In no event shall the author(s) be liable for any
// claim, damages, or other liability, whether in an action of
// contract, tort, or otherwise, arising from, out of, or in connection
// with the software or the use or other dealings in the software.
//
// SUPPORT
// Send bug reports to: <[email protected]>
//


#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

#include <windows.h>
#include <tchar.h>
#include <winioctl.h>

// Get first CD-ROM Drive letter
TCHAR GetCDROM()
{
TCHAR buff[4];
TCHAR i;

_tcscpy(buff, "X:\\");

for(i = _T('A'); i <= _T('Z'); i++)
{
buff[0] = i;
if(GetDriveType(buff) == DRIVE_CDROM)
return i;
}

return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

TCHAR buff[7];
HANDLE hDevice;

// Create a CD-ROM drive string
_tcscpy(buff, "\\\\.\\X:");
buff[4] = GetCDROM();

if(buff[4] == 0)
{
MessageBox(NULL, _T("No CD-ROM drives found on system."), _T("Eject"),
MB_OK | MB_ICONSTOP);
return 2;
}

// Open the CD device
hDevice = CreateFile(buff, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);

if(hDevice != INVALID_HANDLE_VALUE)
{
DWORD code = IOCTL_STORAGE_EJECT_MEDIA;
DWORD bytesRet = 0;

// If specified with the '-load' parameter then load
// the drive rather than eject
if(strstr(lpCmdLine, "-load"))
code = IOCTL_STORAGE_LOAD_MEDIA;

DeviceIoControl(hDevice, code, NULL, 0, NULL, 0, &bytesRet, NULL);
}

return 0;
}
 
S

Swifty

Mark said:
I know of no software interface to close it.

Try wizmo from Gibson Research.

wizmo quiet close

I put "open" and "close" on keystrokes Ctrl+J and Ctrl+Shift+J (J for
eJect) using "The Wonderful Icon".

I'm just too lazy to reach over to poke the button on the drive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top