none
Windows API to detect a removable disk(displayed as Local Disk) RRS feed

  • Question

  • There are many USB drives displayed as Local Disk not Removable Disk in Windows, especially these USB drives with Windows 8 Compatibility logo. So when I try to detect a Removable Disk in my .Net(C#) program, I can not detect one even though the USB drive has been inserted in my computer. So I want to know whether there is a Windows API that can detect a USB drive(displayed as Local Disk) or Windows how to resolve this question. Does anyone know?
    Friday, March 28, 2014 5:24 AM

Answers

  • I don't think it'll help because the firmware of these drive really list themselves as non-removable, possibly because of the defination change in WDK documentation (Read usage on FILE_REMOVABLE_MEDIA, where it expliciltly called out this shouldn't be assigned for flash drives).

    I'm interested to see if there's working solution to this problem too.

    EDIT: The answer involving query on SPDRP_REMOVAL_POLICY in this reply seems promising. Please come back to update that post whether it works for you or not.

    EDIT2: Seems that's against Microsoft's recommandation so it's another no-go. See if the suggestion at the bottom here involving IOCTL check on bus type works for you.


    Monday, March 31, 2014 6:36 AM
    Answerer

All replies

  • Hello,

    I am not sure whether there is such API, in C#, we can use the DriveInfo as:

    var result= DriveInfo.GetDrives().Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);

    This will return a list of all removable devices that are currently accessible.

    If you want to know more information, you can check below links:

    The DriveInfo:

    http://msdn.microsoft.com/en-us/library/system.io.driveinfo(v=vs.110).aspx

    Hope this will be helpful.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 31, 2014 3:33 AM
    Moderator
  • I don't think it'll help because the firmware of these drive really list themselves as non-removable, possibly because of the defination change in WDK documentation (Read usage on FILE_REMOVABLE_MEDIA, where it expliciltly called out this shouldn't be assigned for flash drives).

    I'm interested to see if there's working solution to this problem too.

    EDIT: The answer involving query on SPDRP_REMOVAL_POLICY in this reply seems promising. Please come back to update that post whether it works for you or not.

    EDIT2: Seems that's against Microsoft's recommandation so it's another no-go. See if the suggestion at the bottom here involving IOCTL check on bus type works for you.


    Monday, March 31, 2014 6:36 AM
    Answerer
  • Hello lgjxsq,

    Any update? I have marked cheong00s reply as answer since it seems to be helpful, if you think it provides no help, please unmark it.

    Thank you for your understanding and support.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 8, 2014 9:20 AM
    Moderator