Load CD/DVD Tray

Is there a way to create a Toggle Button that will open AND close a CD ROM tray?

Simply alternate clicking the CD drive will show the option of opening the tray
But nothing about closing the tray again.

I would like to create 2 buttons one for each ROM drive I have (one is virtual)

Thank you for your time.

Cheers :thumbsup:

Well, this is a Windows thing so I don't think you can do that. However, you can use 3rd party software and then make a custom button to do it.

nirsoft.net/utils/nircmd.html
This is a software by NirSoft (who is a reputable developer that makes many many tools for Windows). It's a command line tool that allows you to do various things such as opening and closing drives, speak text, change volume, turn on/off monitors, reboot/turn off computer, and various other things.

  1. Download nircmd and extract it into C:\Windows so that you can call it anytime from the command prompt anytime.

Make a new cascade button menu with a button that runs the command
nircmd cdrom open D: (replace D with whatever drive you want)

Make another button in that cascade button menu to run:
nirsoft.net/utils/nircmd.html
nircmd cdrom close D: (replace D with whatever drive you want)

Now make another cascade button menu for your virtual drive.

Voila!

You can also try this with scripting. It is always possible to access almost all underlying Windows functions/API via scripting so you don't need to download any third-party stuff.

I've found the relevant code here: superuser.com/a/972502 (see non-powershell example)
And I've tried to make an Opus button that opens all CD drives and it works.

Use this code in a button (make sure to set Script Function and jscript in "function" option for your button);

[code]var oSH = new ActiveXObject('Shell.Application'),
FSO = new ActiveXObject('Scripting.FileSystemObject'),
CDdriveType = 4,
ssfDRIVES = 17,
drives = new Enumerator(FSO.Drives);

while (!drives.atEnd()) {
var x = drives.item();
if (x.DriveType == CDdriveType) {
oSH.NameSpace(ssfDRIVES).ParseName(x.DriveLetter + ':').InvokeVerb('Eject');
while (x.IsReady)
WSH.Sleep(50);
}
drives.moveNext();
}
[/code]
This example opens all CD drives. It should be trivial for you to modify it so that it opens or closes tray of your desired drive(s).

Screenshot of button setup:



I've also attached the button as file if you need it (just remove .txt extension and drag & drop it on your Opus toolbar when in Customize mode).
Eject All CD drives.dcf.txt (1.16 KB)

Ah sorry I see you also want to close it, that would require different approach. I don't have code ready for this but here is the clue how to go about it: superuser.com/a/526548

Of course, Enternal's solution to use the nircmd would be quickest and easiest :slight_smile:

Thank you all for the suggestions.
In the end I took Enternal's suggestion.
I loaded the nircmd (it must be in the windows folder for some reason) :unamused:
The I just made custom buttons to open and close the tray.

Thank you!

It doesn't need to be in the Windows folder, you'd just need to specify the full path to the exe, not just the name, for it to be found.

Sorry I wasn't clear about it. I personally put it into the Windows folder so that I can simply call it up nircmd without having to refer to the full path if I put it elsewhere (unless that path is also in the systems PATHS). Basically if you were to put it elsewhere, like leo said, just put the full path of nircmd into the button and it should work out fine.

Also, jsys, that seems pretty cool and neat!

Thank you jsys. Works great. You should add it to the Script Buttons & Add-Ins downloads page.

I've been using this little program for some time digola.com/doorcontrol.html, works fine.

[quote="Enternal"]Sorry I wasn't clear about it. I personally put it into the Windows folder so that I can simply call it up nircmd without having to refer to the full path if I put it elsewhere (unless that path is also in the systems PATHS). Basically if you were to put it elsewhere, like leo said, just put the full path of nircmd into the button and it should work out fine.

Also, jsys, that seems pretty cool and neat![/quote]

For years now, on all my computers, I've been adding a "Programs" folder under my user profile (shortcut in DOpus is to go to "/profile"). I've added that folder to the system's PATH environment variable. I use this as a location for programs that don't have an installer (like command line utilities). I much prefer this method than putting stuff in the Windows folder because I would rather leave my Windows folder intact and untouched.