Reputation: 175
I'm using GetDriveTypeA("D:\\")
to check the existence of the "preserved D" drive, but it's always exist, even when a disk is not inserted into it. Why? It's even not visible in the Disk management when a disk is not inserted.
Upvotes: 0
Views: 116
Reputation: 596823
Just because a removable disk is not inserted does not mean the drive itself, or its assigned drive letter, does not exist. Windows system UIs may hide drives with ejected media (what management is the user going to perform on a drive without media?), but code can still interact with such drives if needed. That is why GetDriveType()
does not fail if D:
has been assigned to a drive.
If you really need to check if a disk is inserted, do something that requires a disk (like query the disk space, or the disk volume information), or drop to the MMC layer and use DeviceIoControl()
to ask the drive directly if it has a disk inserted or not (and if needed, what type of disk).
Upvotes: 1