DelphiFAQ Home Search:

Detecting a CDROM and other drives (newer Windows versions)

 

comments2 comments. Current rating: 4 stars (2 votes). Leave comments and/ or rate it.

The following code enumerates the drives on the local computer using the Windows API GetDriveType. This function was introduced with Windows 95 already, so there is no need to use the other code posted on this site (which was written for Windows 3.1 and worked until Windows 98).

procedure TForm1.Button1Click(Sender: TObject);
var
  i,
  iType: integer;
  s: String;
begin { TForm1.Button1Click }
  for i := 0 to 25 do
  begin
    s := Chr(i + 65) + ':';
    iType := GetDriveType(PChar(s));
    case iType of
      DRIVE_REMOVABLE:
        ListBox1.Items.Add(Chr(i + 65) + ': floppy');
      DRIVE_FIXED:
        ListBox1.Items.Add(Chr(i + 65) + ': hard disk');
      DRIVE_CDROM:
        ListBox1.Items.Add(Chr(i + 65) + ': CDROM');
      DRIVE_RAMDISK:
        ListBox1.Items.Add(Chr(i + 65) + ': RAMDisk');
      DRIVE_REMOTE:
        ListBox1.Items.Add(Chr(i + 65) + ': network drive');
    end; { case iType }
  end; { for i }
end; { TForm1.Button1Click }
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-03-23, 20:37:27
anonymous from Indonesia  
rating
Its work on WinXP SP2, very useful
2006-04-23, 01:13:20
anonymous from Netherlands  
rating
You can also use GetLogicalDriveStrings and then use GetDriveType for each drive found. / Louis.

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.