Solved

Drives

Posted on 1998-08-03
5
155 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
Comment Utility
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
Comment Utility
I get a "File not found" error. How can I fix it?
0
 

Author Comment

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

Accepted Solution

by:
vinoopauls earned 50 total points
Comment Utility
   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
Comment Utility
cool thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now