Link to home
Start Free TrialLog in
Avatar of khalil_moghaddam
khalil_moghaddam

asked on

How can I Check a virtual drive

I Want to ensure :

Is a drive a real (not virtual or device driver) drive? hard disk or cd drive
Avatar of SuperUt
SuperUt

In the Windows unit you'll find
function GetDriveType(lpRootPathName: PChar): UINT; stdcall;

The result is one of these:
DRIVE_UNKNOWN  The drive type cannot be determined.
DRIVE_NO_ROOT_DIR  The root path is invalid. For example, no volume is mounted at the path.
DRIVE_REMOVABLE  The disk can be removed from the drive.
DRIVE_FIXED  The disk cannot be removed from the drive.
DRIVE_REMOTE  The drive is a remote (network) drive.
DRIVE_CDROM  The drive is a CD-ROM drive.
DRIVE_RAMDISK  The drive is a RAM disk.

Hope this does it.
unit Unit_Q_20946070;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm_CD = class(TForm)
    Btn_Scan_Devices: TButton;
    Memo_Devices: TMemo;
    procedure Btn_Scan_DevicesClick(Sender: TObject);
  private  { Private declarations }
  public   { Public declarations }
    procedure Scan_Devices;
  end;

var
  Form_CD: TForm_CD;

implementation

{$R *.dfm}

procedure TForm_CD.Scan_Devices;
var
  C:                           Char;
  DriveType:                   DWORD;
  PCRootPathName:              PChar;
  SDriveType:                  string;
  S:                           string;
begin
  Memo_Devices.Clear;
  try
    for C := 'D' to 'Z' do
    begin
      S := C + ':\';
      PCRootPathName := PChar(S);
      DriveType := GetDriveType(PCRootPathName);
      case DriveType of
        0:                   SDriveType := '???'; // 'The drive type cannot be determined.';
        1:                   SDriveType := 'The root directory does not exist';
        DRIVE_REMOVABLE: SDriveType := 'FDD'; // 'The drive can be removed from the drive.';
        DRIVE_FIXED:         SDriveType := 'HDD'; // 'The disk cannot be removed from the drive.';
        DRIVE_REMOTE:         SDriveType := 'NET'; // 'The drive is a remote (network) drive.';
        DRIVE_CDROM:     SDriveType := 'CDD'; // 'The drive is a CD-ROM drive.';
        DRIVE_RAMDISK:   SDriveType := 'RAM'; // 'The drive is a RAM disk.';
      end;
      if (DriveType>1) then
        Memo_Devices.Lines.Add(S + ' is a ' + SDriveType)
      else
        Memo_Devices.Lines.Add(S + SDriveType);
   end;
  except
    on E : Exception do
      ShowMessage(E.Message);
  end;
end;

procedure TForm_CD.Btn_Scan_DevicesClick(Sender: TObject);
begin
  Scan_Devices;
end;

end.
object Form_CD: TForm_CD
  Left = 219
  Top = 114
  Width = 696
  Height = 480
  Caption = 'Form_CD'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Btn_Scan_Devices: TButton
    Left = 24
    Top = 16
    Width = 96
    Height = 25
    Caption = 'Scan Devices'
    TabOrder = 0
    OnClick = Btn_Scan_DevicesClick
  end
  object Memo_Devices: TMemo
    Left = 134
    Top = 14
    Width = 531
    Height = 407
    TabOrder = 1
  end
end
ooops, replace
>    for C := 'D' to 'Z' do
with
    for C := 'A' to 'Z' do (Including FDD)
or
    for C := 'C' to 'Z' do
Avatar of khalil_moghaddam

ASKER

But This Function can't recognize a virtual drive application linke CloneCd (a burning CD app.) it recognize it az an CD drive
But This Function can't recognize a virtual drive like CloneCd (a burning CD app.) it recognize it az an CD drive
I think this application does a good camouflage of the virtual drive like CloneCd ;-))

emil
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial