I have the following script that I use to determine drive types. Most USB drives return as a Removable Drive type, but the Lexar Jumpdrive returns as a Fixed Drive. Does anyone know of a better way to determine if a removable drive is plugged in to the computer (Camera, USB Drive, etc)? Is there a way to determine if a removable drive is a USB drive?
use strict;
use Win32::API;
$|=1;
binmode(STDOUT);
getDrivesInUse();
###############
sub getDrivesInUse{
my (@dr, $i);
my %DriveType=(
1=>"Unknown Root",
2=>"Removable",
3=>"Fixed",
4=>"Mapped",
5=>"CDRom",
6=>"RAMDisk",
);
my $GetLogicalDrives = new Win32::API("kernel32", "GetLogicalDrive
+s", [], 'N') || return $^E;
my $bitmask = $GetLogicalDrives->Call();
print "bitmask:\r\n$bitmask\r\n\r\n";
for $i(0..31) {
if ($bitmask & 2**$i){
my $drive=chr(ord("A")+$i);
my $type=getDriveType($drive);
print "$i\. Drive: $drive [$type][$DriveType{$type}]\r\n";
}
}
}
###############
sub getDriveType ($) {
my $drive = shift;
return undef unless $drive =~ s/^([a-z])(:(\\)?)?$/$1:\\/i || $dri
+ve =~ s/^(\\\\\w+\\\w+\$?)(\\)?$/$1\\/;
my $GetDriveType = new Win32::API("kernel32", "GetDriveType", ['P'
+], 'N') or return;
my ($lpDirectoryName) = $drive;
my $type = $GetDriveType->Call( $lpDirectoryName );
return $type;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.