CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Apr 2006
    Posts
    28

    Question 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

  2. #2
    Join Date
    Feb 2001
    Posts
    2,455

    Re: Tio disable the manual eject of the CD ROM

    Quote 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

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Tio disable the manual eject of the CD ROM

    Quote 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

  4. #4
    Join Date
    Apr 2006
    Posts
    28

    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

  5. #5
    Join Date
    May 2005
    Posts
    4,954

    Re: Tio disable the manual eject of the CD ROM

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Tio disable the manual eject of the CD ROM

    Quote 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

  7. #7
    Join Date
    Apr 2006
    Posts
    28

    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.

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    Re: Tio disable the manual eject of the CD ROM

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Tio disable the manual eject of the CD ROM

    Quote 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

  10. #10
    Join Date
    Apr 2006
    Posts
    28

    Question 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

  11. #11
    Join Date
    May 2005
    Posts
    4,954

    Re: To disable the manual eject of the CD ROM

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  12. #12
    Join Date
    Apr 2006
    Posts
    28

    Question 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 );
    }
    }
    }

  13. #13
    Join Date
    May 2005
    Posts
    4,954

    Re: Tio disable the manual eject of the CD ROM

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  14. #14
    Join Date
    Apr 2006
    Posts
    28

    Question Re: Tio disable the manual eject of the CD ROM

    When I debugged I got the error was " Access is denied. "

  15. #15
    Join Date
    May 2005
    Posts
    4,954

    Re: Tio disable the manual eject of the CD ROM

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured