Solved

Drives

Posted on 1998-08-03
5
159 Views
Last Modified: 2010-05-03
In my program, I need to run a scan on all drives available on a system. How do I figure out which drives are there or not? For Floppy disk drives and CD ROM Drives I need to check if it is accessable, or disk loaded into it. Thanks for your help
0
Comment
Question by:Hanky363
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1467685
You need to use the GetDriveType API call:

Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Then you can do something like this:
dim d as integer
dim s as string
dim r as long
for d=0 to 25
    ' here 0 means drive A:, 1 is drive B:, etc...
    s = chr$(d+65) & ":"
    r = GetDriveType(s);
    if r = 2 then
        ' This is a removable drive (floppy, ZIP, etc...)
    elseif r = 3 then
        ' This is a hard drive
    elseif r = 4 then
        ' This is a network drive
    elseif r = 5 then
        ' This is a CD-ROM drive
    elseif r = 6 then
        ' This is a virtual RAM drive
    else
        ' Drive does not exist
    end if
next d

To check whether, for example a diskette is in a floppy drive, you can try reading a directory from that diskette (say, dir *.*) and catch the errors.  If an error occurs, then there is no diskette in the drive.
0
 

Author Comment

by:Hanky363
ID: 1467686
I get a "File not found" error. How can I fix it?
0
 

Author Comment

by:Hanky363
ID: 1467687
I am using VB 3.0 16-bit if that makes a difference
0
 

Accepted Solution

by:
vinoopauls earned 50 total points
ID: 1467688
   Put the Drive list box in the form. This will give the list of valid drives in the system.
Scan each drive thru a loop and check for error codes and trap them. The following error codes should help
    57-Device I/O Error
    68-Device Unavailable

Hope this helps
0
 

Author Comment

by:Hanky363
ID: 1467689
cool thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question