We know USB disk should be a removable disk just like floppy disk, and be used
more and more widely now. Because, the USB disk is more faster,
reliable, and affordable than old floppy disk.
So, when we want to check one disk or drive of target system is removable
or not, we may be thinking of using API function "
it really works on some USB device, such as 16MB, <st1:place w:st="on"><st1:city
w:st="on">32<st1:state w:st="on">MB, <st1:postalcode
and 128MB. ;-) Here, how about removable hard disk which is connected
to system by USB channel? - Windows will report them as 'Fix Disk', and we
would get the same result using '
How can we differentiate between these USB ‘Fix Disk’ and Those IDE ‘Fix Disk’?
Here is the solution for this event.
do I want get the USB disks' drive letter properly? Because I want to check
the virus while one new USB drive is inserted. We should not be remiss of
the virus which is more and more technical day by day:)
Since we can get the base
information about the disk type (using API Function
we may only want to check the ‘Removable Hard Disk’ to verify its bus-type.
Well, we’ll have two steps to get the USB disk’s drive letters:
the disks base information:
switch ( GetDriveType( szDrvName ) )
drivetype = DRVUNKNOWN;
drivetype = DRVREMOVE;
drivetype = DRVFIXED;
drivetype = DRVREMOTE;
drivetype = DRVRAM;
These codes above are based on ‘Article ID: Q161300 HOWTO: Determine the
Type of Drive Using Win<st1:chmetcnv w:st="on" unitname="’"
sourcevalue="32" hasspace="False" negative="False" numbertype="1"
tcsc="0">32’ from MSDN.
the bus type of the ‘Fix Disk’:
Now, we may embed our codes at the ‘
case = DRIVE_FIXED’:
Open the drive which we get now:
hDevice = CreateFile(szBuf,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, NULL, NULL);
If we opened this drive, check its
BUSTYPE, using API
if(pDevDesc->BusType == BusTypeUsb)
szMoveDiskName[k] = chFirstDriveFromMask(temp);
Close this drive when we finished our work on it:
How does the GetDisksProperty() work?
BOOL GetDisksProperty(HANDLE hDevice,
Query.PropertyId = StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;
bResult = ::DeviceIoControl(hDevice,
- There are some structures not commented, see usbdisks_src for
- Floppy drive (A: or B:) is reported as USB Disks by this
-And- it is easy to correct this, just
some codes to the ‘
case = DRIVE_REMOVABLE:‘;