none
CreateFile returns ACCESS_DENIED when trying to open a device handle on Windows 8 RRS feed

  • Question

  • Hello,

    I am trying to access a device handle on Windows 8 using CreateFile, so I can use it in DeviceIOControl to send commands to an optical drive. The existing code works in Windows 7, but CreateFile returns ACCESS_DENIED in Windows 8. It works if I run it as an administrator, but this may not be an option for many of our users.

    For example, what we've been using is:

    Handle = CreateFileW (DevicePath, 
                             GENERIC_WRITE|GENERIC_READ,
                             FILE_SHARE_READ|FILE_SHARE_WRITE,
                             NULL, OPEN_EXISTING,
                             0,
                             NULL);
    
    RetVal = DeviceIoControl (Handle,
                                IOCTL_SCSI_GET_CAPABILITIES,
                                &ScsiCapabilities,
                                sizeof(ScsiCapabilities),
                                &ScsiCapabilities,
                                sizeof(ScsiCapabilities),
                                &ReturnedBytes,
                                NULL);
    

    Not being able to get the device handle has been our biggest hurdle in getting our software running on Windows 8.

    Is there a workaround we could use?

    Note: This is for a desktop app, not a metro app.

    Wednesday, January 16, 2013 11:13 PM

Answers

  • what is the DevicePath? there is no real work around, if you are getting ACCESS_DENIED, then you pretty much have to run as admin/elevated.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, January 17, 2013 12:17 AM

All replies

  • what is the DevicePath? there is no real work around, if you are getting ACCESS_DENIED, then you pretty much have to run as admin/elevated.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, January 17, 2013 12:17 AM
  • DevicePath is usually something like: IDE\CdRomPLDS_BD-RE_DH-8B2SH_____________________SD11____\4&2e847d9b&0&0.0.0

    Thursday, January 17, 2013 5:22 PM
  • are you opening up a device interface instance?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, January 17, 2013 7:29 PM