-
May 19th, 2006, 09:25 AM
#1
Tio disable the manual eject of the CD ROM
Dear All,
In my application I want disable the manual eject of my CD ROM wha do I do?
Please help
-
May 19th, 2006, 10:43 AM
#2
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
Dear All,
In my application I want disable the manual eject of my CD ROM wha do I do?
Please help
I don't know how this works, but one thing concerns me. I can imagine that this is done by setting a system variable? If so, if you programmatically change this setting and your application terminates unexpectedly, wouldn't you be essentially locking the CD-ROM drive?
Mike B
-
May 19th, 2006, 11:19 AM
#3
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
In my application I want disable the manual eject of my CD ROM wha do I do?
First you read MSDN, I suppose.
IOCTL_STORAGE_EJECTION_CONTROL
Best regards,
Igor
-
May 22nd, 2006, 06:07 AM
#4
Re: Tio disable the manual eject of the CD ROM
I tried IOCTL_STORAGE_EJECTION_CONTROL. but in this method I need a handle of the device . In MSDN it is said to use CreateFile, In CreateFile we need to give the volume name as parameter . But How I can find the volume name of the CD ROM.
I was not able to use GetVolumeNameForVolumeMountPoint, some compilation error occured
-
May 22nd, 2006, 06:12 AM
#5
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
I tried IOCTL_STORAGE_EJECTION_CONTROL. but in this method I need a handle of the device . In MSDN it is said to use CreateFile, In CreateFile we need to give the volume name as parameter . But How I can find the volume name of the CD ROM.
I was not able to use GetVolumeNameForVolumeMountPoint, some compilation error occured
You can use ::GetDriveType() to determine which device is the CDROM. ( simple loop from ‘A’ to ‘Z’ )
Cheers
-
May 22nd, 2006, 06:30 AM
#6
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
I tried IOCTL_STORAGE_EJECTION_CONTROL. but in this method I need a handle of the device . In MSDN it is said to use CreateFile, In CreateFile we need to give the volume name as parameter . But How I can find the volume name of the CD ROM.
Well, then why do you need drive locking? I thought you wanna lock drive to guarantee some path is available for your program. But in this case you know what path you protect. Can't you extract device name from your path?
Best regards,
Igor
-
May 22nd, 2006, 07:24 AM
#7
Re: Tio disable the manual eject of the CD ROM
I tried that . In my system my CD Drive letter is "G" . I gave "G:\" as the parameter to createFile but the call failed and from the GetLasterror I found that my path is wrong.
-
May 22nd, 2006, 07:44 AM
#8
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
I tried that . In my system my CD Drive letter is "G" . I gave "G:\" as the parameter to createFile but the call failed and from the GetLasterror I found that my path is wrong.
You should be calling ::CreateFile() like that:
Code:
HANDLE hCDRom = ::CreateFile("\\\\.\\G:",0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
NOTE: I opened it with FILE_SHARE_READ if you need something else refer to MSDN for the other parameters of ::CreateFile().
Cheers
-
May 22nd, 2006, 08:50 AM
#9
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
I tried that . In my system my CD Drive letter is "G" . I gave "G:\" as the parameter to createFile but the call failed and from the GetLasterror I found that my path is wrong.
See CreateFile, Physical Disks and Volumes section about volume name rules. I belive, it would be done first before any further asking.
Best regards,
Igor
-
May 22nd, 2006, 10:07 AM
#10
Re: To disable the manual eject of the CD ROM
Sombody please help me with the full code block, I tried all the way I could but failed . please help
-
May 22nd, 2006, 10:52 AM
#11
Re: To disable the manual eject of the CD ROM
Originally Posted by rrapheall
Sombody please help me with the full code block, I tried all the way I could but failed . please help
Did you look at my post? there is a sample code that works assuming that your cdrom drive letter is G.
If it still doesn’t help please post the code you are using.
Cheers
-
May 22nd, 2006, 11:25 AM
#12
Re: Tio disable the manual eject of the CD ROM
void CEjectBlockDlg::OnButton1()
{
PREVENT_MEDIA_REMOVAL a;
a.PreventMediaRemoval = true;
OVERLAPPED Overlapped;
m_hFile = ::CreateFile("\\\\.\\G:",0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (m_hFile != INVALID_HANDLE_VALUE)
{
if( !DeviceIoControl(
(HANDLE) m_hFile,
IOCTL_STORAGE_EJECT_MEDIA,
(LPVOID) &a,
(DWORD) sizeof( a ),NULL,0,NULL,NULL))
{
DWORD a = GetLastError();
CString cs;
cs.Format( "%d" , a );
AfxMessageBox( cs );
}
}
}
-
May 22nd, 2006, 01:09 PM
#13
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
void CEjectBlockDlg::OnButton1()
{
PREVENT_MEDIA_REMOVAL a;
a.PreventMediaRemoval = true;
OVERLAPPED Overlapped;
m_hFile = ::CreateFile("\\\\.\\G:",0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (m_hFile != INVALID_HANDLE_VALUE)
{
if( !DeviceIoControl(
(HANDLE) m_hFile,
IOCTL_STORAGE_EJECT_MEDIA,
(LPVOID) &a,
(DWORD) sizeof( a ),NULL,0,NULL,NULL))
{
DWORD a = GetLastError();
CString cs;
cs.Format( "%d" , a );
AfxMessageBox( cs );
}
}
}
And what exactly not working? Did you step in debugger to see whats going on?
Cheers
-
May 22nd, 2006, 10:29 PM
#14
Re: Tio disable the manual eject of the CD ROM
When I debugged I got the error was " Access is denied. "
-
May 23rd, 2006, 01:08 AM
#15
Re: Tio disable the manual eject of the CD ROM
Originally Posted by rrapheall
When I debugged I got the error was " Access is denied. "
Something is not clear to me, if you want to disable eject cdrom you need to use the IOCTL_STORAGE_EJECTION_CONTROL like already suggested, and in your sample you using IOCTL_STORAGE_EJECT_MEDIA. If you want to use the IOCTL_STORAGE_EJECT_MEDIA read the documentation in MSDN you should not pass the PREVENT_MEDIA_REMOVAL parameter since it working with IOCTL_STORAGE_EJECTION_CONTROL and not with IOCTL_STORAGE_EJECT_MEDIA so obviously there is a confusion here
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|