Q:

Detect when CD drive was closed

So I am making a little project for myself. I need to detect if the CD Drive was closed, and if it was, run a function. 
Is this possible?

A:

First you will need to define the function that will be opening the disk tray:
[DllImport("winmm.dll", EntryPoint = "mciSendString")]
public static extern int mciSendStringA(string lpstrCommand, string lpstrReturnString, 
                            int uReturnLength, int hwndCallback);

To close(or check if the drive is closed) the disk drive you need to send two command strings .
mciSendStringA("open " + driveLetter + ": type CDaudio alias drive" + driveLetter, 
                 returnString, 0, 0);
mciSendStringA("set drive" + driveLetter + " door closed", returnString, 0, 0);

The function returns0 if the command is successfully executed or else it returns an error code.So you can have a logic to check that.
You can check the documentation of the function  and also a useful link for more info

