talkerzero Grandmaster Cheater Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Sep 20, 2009 10:36 am Post subject: CD Tray Opener |
|
|
This will enumerate through all the drives, check for the first CD-ROM/DVD drive, and open the CD tray (eject the disc on newer laptops).
[http://www.sendspace.com/file/hrim6m]
Code: | #include <windows.h>
#include <winioctl.h>
#include <stdio.h>
#include <tchar.h>
int __cdecl _tmain(__in int argc, __in_ecount_z_opt(argc) _TCHAR* __targv[], __in_z_opt _TCHAR* __tenviron[])
{
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(__targv);
UNREFERENCED_PARAMETER(__tenviron);
TCHAR szDrive[] = _T("C:\\");
TCHAR szCDDrive[] = _T("\\\\.\\d:");
HANDLE hDrive;
DWORD dwBytesReturned;
BOOL bRet = FALSE;
INT i = 0;
for(i = 0; i < 26; i++)
{
_stprintf_s(szDrive, _T("%c:\\"), (CHAR)('A' + i));
if(GetDriveType(szDrive) == DRIVE_CDROM)
{
_stprintf_s(szCDDrive, _T("\\\\.\\%c:"), ('A' + i));
_tprintf(_T("CD-ROM drive detected: [%c:\\]\n"), (CHAR)('A' + i));
break;
}
}
hDrive = CreateFile(szCDDrive, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if(hDrive != INVALID_HANDLE_VALUE)
bRet = DeviceIoControl(hDrive, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
if(!bRet)
_ftprintf(stderr, _T("Failed to eject drive.\n"));
else
_tprintf(_T("Successfully ejected drive.\n"));
_gettchar();
return (bRet ? EXIT_SUCCESS : EXIT_FAILURE);
} |
|
|