i have small testing script to eject/load a cd drive.
Code:
#include "stdafx.h"
#include "windows.h"
#include "Winioctl.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
HANDLE drive_file;
BOOL success;
DWORD temp;
char drive_letter[7] = "\\\\.\\D:";
// Open Target Drive
drive_file = CreateFile(drive_letter, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (drive_file != INVALID_HANDLE_VALUE) {
while (success) {
// Eject or Load the CD
success = DeviceIoControl(drive_file, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &temp, NULL);
if (success) {
Sleep(2000);
success = DeviceIoControl(drive_file, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &temp, NULL);
if (success) Sleep(2000);
}
}
}
return 0;
}
Shure i could walk thru D to Z or use GetLogicalDrives()/GetLogicalDriveStrings() and then GetDriveType() == DRIVE_CDROM
But isn't there a easier way ?