MiDaTi
asked on
Is a drive a USB drive?
I need to check to see if a drive is connected via USB. According to the documentation for GetDriveType you need to call SetupDiGetDeviceRegistryPr operty and specify the SPDRP_REMOVAL_POLICY property. I'm not having any luck getting this to work. Can someone post a function that accepts a drive letter and returns TRUE if the drive is connected via USB.
ASKER
Sorry, but you've misunderstood the question. I don't want to know when a USB device is connected, I want to know if a drive is connected via USB.
ASKER
Just to clarify further: I want to know if an already connected drive is connected via USB, e.g. it is a USB thumb drive. I don't need (or want) to know when it is connected or disconnected. According to the Win32 API documentation you need to use SetupDiGetDeviceRegistryPr operty to find this out.
can you use that simple solution
{*******************************************************************************
* Read all the drive in a computer system ,
* V 1.0 incl. removable drives like Floppy or USB Stick
*
*******************************************************************************}
function GetDriveList : TStringList;
var DriveList : TStringList;
I,Typ : Integer;
s : String;
begin
try
DriveList:= TStringList.Create;
DriveList.Clear;
For i := 0 To 25 do
begin
s := Chr(i + 65) + ':\';
typ := GetDriveType(PChar(s));
If Typ <> 0 Then
Case Typ of
DRIVE_REMOVABLE :
DriveList.Add(Chr(i + 65) + ': Floppy/USB');
DRIVE_FIXED :
DriveList.Add(Chr(i + 65) + ': HARD DISC');
DRIVE_CDROM :
DriveList.Add(Chr(i + 65) + ': CDROM');
DRIVE_RAMDISK :
DriveList.Add(Chr(i + 65) + ': RAM DISC');
DRIVE_REMOTE :
DriveList.Add(Chr(i + 65) + ': NET DRIVE');
end;
end;
finally { free ? }
Result := DriveList;
end;
end;
ASKER
No, this will not work. GetDriveType returns DRIVE_FIXED for a USB key (it does for me on XP SP3). As per the Win32 documentation for GetDriveType: you need to call SetupDiGetDeviceRegistryPr operty and specify the SPDRP_REMOVAL_POLICY property to discover if it is connected via USB.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
https://www.experts-exchange.com/questions/21552015/How-to-Monitor-if-a-USB-device-is-plugged-in.html?sfQueryTermInfo=1+drive+letter+usb