Windows – How to Detect Duplicate Drive Letters

cdrive-letterwindows

There is a small bug in Windows that I would like to create a small application as a solution for. So, in my company we have several network drives ( F:\, G:\, H:\, I:\ etc.) and sometimes if I connect an external USB device such as a card reader, windows will assign an already used drive letter. So for example, I have a network drive F:\, and I connect my card reader which windows will also assign F:\ to this device, so I cant use that USB device, until I change it's drive letter.

So my question's are:

  • How can I detect these devices or drive letters when they are assigned twice?
  • How can I detect which one of them is a USB device?
  • How can I reassign a drive letter to that device?

I want to do this in C.

Thanks.

Best Answer

most of what you want can be done with FindFirstVolume and its friends (the example here covers everything), to get the type, you would use GetDriveType, then finally SetVolumeMountPoint will rename a device drive letter.

Related Question