How to programatically check if a pen-drive is connected?

Hi Experts!

Do you know a programatically way to check if a pen-drive is connected ?

Thanks in advance!
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You'll need more functions probably...

DISKSPACE("D:") returns -1 if the given drive is NOT connected otherwise it returns free or total disk space in bytes.

DRIVETYPE("D:")  returns drive type (see VFP help for available values) but USB drives are returned as removable drive so you cannot distinguish it from floppy disk in may cases...

Above two functions should be sufficient enough to decide whether or not to check for / write to a file on the disk.

If you really need exact drive type then you'll probably need to check the hardware alone by WMI or Win32 API functions. Remember the hardware is accessible via software driver and the driver decides what return value provides to you...

This function could be of your interest:
USB is returned as Media type 11, floppy disks have many other values:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Olaf DoschkeSoftware DeveloperCommented:
What I use is DryiveType() and check for drive type = 2. That's mostly sufficient. Another thing is a WMI query Select * From Win32_LogicalDisk Where DriveType = 2, again checking Drivetype. You can go more into details, if it's Diskspace just is 1.44MB it's floppy, but who uses floppies anymore? If you want to detect pen vs external hdd, that's harder, pen drive today come in sizes only hdds had, buit that shouldn't matter much.

Bye, Olaf.
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Thank you very much for your always very precise assistance!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.