title: CM_Request_Device_Eject fails with PNP_VetoIllegalDeviceRequest
body: <p>I tried the code below. It requests ejection when the device name contains &quot;San&quot;, because I have plugged in a SanDisk USB drive. However it fails, and the reason seems to be <code>PNP_VetoIllegalDeviceRequest</code>. I looked up the reason, and <a href="https://docs.microsoft.com/en-us/windows/win32/api/cfg/ne-cfg-pnp_veto_type" rel="nofollow noreferrer">this page</a> says it is</p>
  <blockquote>
  <p>The device does not support the specified operation.</p>
  </blockquote>
  <p>But I can manually eject the SanDisk using Windows' menu, so the reason seems absurd. Did I call the function correctly? Do I need to call something else before calling <code>CM_Request_Device_Eject</code>?</p>
  <p>The output was</p>
  <pre><code>....
  SanDisk Ultra USB Device
  Removing Sandisk
  rejected.
  type:8
  name:USBSTOR\Disk&amp;Ven_SanDisk&amp;Prod_Ultra&amp;Rev_1.00\....
  </code></pre>
  <p>The code was (the value of <code>Devinst</code> was <code>3</code>)</p>
  <pre><code>    if (wcsstr(buffer, L&quot;San&quot;) != 0)
      {
          wcout &lt;&lt; &quot;Removing Sandisk&quot; &lt;&lt; endl;
          PNP_VETO_TYPE vType;
          WCHAR vName[MAX_PATH];
          result = CM_Request_Device_Eject(Devinst, &amp;vType, vName, MAX_PATH, NULL);
  
          if (result == CR_SUCCESS)
          {
              cout &lt;&lt; &quot;ejected&quot; &lt;&lt; endl;
          }
          else
          {
              wcout &lt;&lt; &quot;rejected.&quot; &lt;&lt; endl;
              wcout &lt;&lt; &quot;type:&quot;&lt;&lt; vType &lt;&lt; endl;
              wcout &lt;&lt; &quot;name:&quot; &lt;&lt; vName &lt;&lt; endl;
          }
      }
  </code></pre>