title: ERROR_ACCESS_DENIED when calling DeviceIoControl with IOCTL_CHANGER_GET_PRODUCT_DATA
body: <p>I have a task to get VendorId and ProductId of devices mounted as disks. Code looks like that:</p>
  
  <pre><code>int main() {
      HANDLE hDevice;
      char cDisk = 'c';   // Get metadata about the C:\ disk
  
                          // Build the logical drive path and get the drive device handle
      std::wstring logicalDrive = L"\\\\.\\";
      wchar_t drive[3];
      drive[0] = cDisk;
      drive[1] = L':';
      drive[2] = L'\0';
      logicalDrive.append(drive);
  
      hDevice = CreateFile(
          logicalDrive.c_str(),
          FILE_READ_ATTRIBUTES,
          0,
          NULL,
          OPEN_EXISTING,
          0,
          NULL);
  
      _tprintf(_T("%s\n"), logicalDrive.c_str());
  
      if (hDevice == INVALID_HANDLE_VALUE)
      {
          std::cerr &lt;&lt; "CreateFile error #" &lt;&lt; GetLastError() &lt;&lt; std::endl;
          system("pause");
          return -1;
      }
  
      // Now that we have the device handle for the disk, let us get disk's metadata  
  
      CHANGER_PRODUCT_DATA dg = { 0 };
      DWORD ioctlJnk;
  
      if (!DeviceIoControl(hDevice,
          IOCTL_CHANGER_GET_PRODUCT_DATA,
          NULL,
          0,
          &amp;dg,
          sizeof(dg),
          &amp;ioctlJnk,
          NULL)
          )
      {
          std::cerr &lt;&lt; "DeviceIoControl error #" &lt;&lt; GetLastError() &lt;&lt; std::endl;
          CloseHandle(hDevice);
          system("pause");
          return -1;
      }
  
      // Success, now print the device manufacturer's name
      std::cout &lt;&lt; dg.VendorId &lt;&lt; std::endl;
      CloseHandle(hDevice);
  }
  </code></pre>
  
  <p>The trouble is that <code>DeviceIoControl</code> function fails and <code>GetLastError</code> returns <code>ERROR_ACCESS_DENIED</code>. It happens with any disk. </p>
  
  <p>What can I do to make this code work? Any other ideas how to get VID &amp; PID through the character of mounted device?</p>
  
  <p>Thanks in advance!</p>