How to detect if file is on removable drive (USB, CD, etc)?

Hello Everyone,

I am playing with OSR example http://www.osronline.com/article.cfm?id=107 of function QueryMountPoint (which works great, thanks OSR!)

I would like to know if particular file is run from removable drive, but I can’t seem to find any IOCTL which will give me that functionality.

My current algorithm is simple, I register image notify callback using PsSetLoadImageNotifyRoutine and I try to check if file path is on removable drive or not.

What I noticed is that in XP device name contains \Device\CdRom or \Device\Harddisk or \Device\Floppy but it’s not the case in Windows 7.

Is there any nice solution for Windows 7? Or some better solution for XP/7 ?

Thanks

To get information if a disk is removable you could use
IOCTL_DISK_GET_DRIVE_GEOMETRY and output structure
DISK_GEOMETRY.MEDIA_TYPE == RemovableMedia

What I noticed is that in XP device name contains \Device\CdRom or \Device\Harddisk or \Device
\Floppy but it’s not the case in Windows 7.

Try to use following names
\?\CdRom1
\?\PhysicalDrive1

Igor Sharovar