Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drives

Posted on 1998-08-03
5
Medium Priority
?
163 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
  • 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

782 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