• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

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 Fuerte
Eduardo Fuerte
2 Solutions
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: http://www.news2news.com/vfp/?example=101&function=866
USB is returned as Media type 11, floppy disks have many other values: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365231(v=vs.85).aspx
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 FuerteAuthor Commented:
Thank you very much for your always very precise assistance!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now