locked
SurpriseRemovalOK to reject USB RRS feed

  • Question

  • How to use 'SurpriseRemovalOK' to reject a USB in VC++?
    • Moved by Helen Zhao Tuesday, July 17, 2012 5:06 AM (From:Visual C++ General)
    Monday, July 16, 2012 4:48 AM

Answers

  • SurpriseRemovalOK is a property the device driver sets on the device that says it is OK for the device be yanked, it has nothing to do with eject (nor reject)


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

    Tuesday, July 17, 2012 7:39 PM
  • A device cannot be removed while a handle is open on it. Unfortunately in Windows you cannot say "this device is just going away, no matter who uses it".  This is how it was designed. There are some hackish ways to force surprise removal, but generally it isn't supported.

    --pa

    Monday, July 23, 2012 10:38 AM

All replies

  • You question is more WDK related than VC++ general. I'd give the advice to ask in the WDK section:

    http://social.msdn.microsoft.com/Forums/en-US/wdk/threads

    Only in case you want to remove a USB flash by software this is a very niche article:

    http://www.codeproject.com/Articles/13839/How-to-Prepare-a-USB-Drive-for-Safe-Removal

    Monday, July 16, 2012 6:54 AM
  • you can also check with the following msdn forum  link

    http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/1c4f5546-a9ee-404e-ab1e-79ec5f927eb3


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    Monday, July 16, 2012 11:13 AM
  • Hi shi-foo,

    According to the description, I’d like to move this thread to "Windows Hardware WDK and Driver Development" forum for better support.

    Thanks for your understanding.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 17, 2012 5:05 AM
  • SurpriseRemovalOK is a property the device driver sets on the device that says it is OK for the device be yanked, it has nothing to do with eject (nor reject)


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

    Tuesday, July 17, 2012 7:39 PM
  • Thanks for the reply Mr. Holan.

    I believe,If SurpriseRemovalOK is set to TRUE, the device can be safely removed from its immediate parent regardless of the state that its driver is in.

    can you please help me,how to set SurpriseRemovalOK to TRUE

    Friday, July 20, 2012 4:35 AM
  • If surprise removal ok is set to true, the device does not show up in the safely remove hardware ui at all.  this is just a property that tells the OS what happens when the device is removed, it doesn't do anything else.  so setting the property on a device which doesn't current set it just means it hides the device from the ui. it doesn't prevent apps from holding on to handles or doing other unfriendly things

    you can only set this property from a driver.

    what bigger problem are you trying to solve?


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

    Friday, July 20, 2012 5:12 PM
  • Actually am trying to reject a 'USB Storage Device', if USB drive path is opened already         (in Vista)

    Current code for rejection is as follows

         ret = CM_Query_And_Remove_SubTree(dinst, &vtype, NULL, NULL, CM_REMOVE_UI_NOT_OK|CM_REMOVE_NO_RESTART);
        if (ret == CR_SUCCESS)
        {
            TCHAR buf[MAX_PATH];
            ret = CM_Request_Device_Eject(dinst, &vtype, buf, MAX_PATH, 0);        
        }

    with the above code 'USB rejection' fails in vista, if USB drive path is opened already

    I hope you can Help me.

    Thanks in Advance

    shi-foo







    Monday, July 23, 2012 4:49 AM
  • Hi Pavel,

    Thanks for the reply.

    This rejection issue arises only in Windows vista.

    With the same code i could reject a USB Storage Device', if USB drive path is opened already  (in Windows XP, Windows 7 32/64 bit).

    [here->USB drive path is opened means, opening the drive using explorer.exe(example: "E:\")]

    Thanks and Regards

    shi-foo

    Tuesday, July 24, 2012 4:19 AM