Is there a way to determine a particular drive's InterfaceType (USB,IDE or SCSI)? Using Win32::API, I can call GetDriveType to tell if it is a fixed drive, cd-rom drive, etc but I need a way to determine whether the drive is USB, IDE, or SCSI. Any ideas?

UPDATE: Taking the excellent comments made, I have been able to come up with the following but when I run it, it accesses the floppy drive every time... I will still need to work on figuring out how to exclude the floppy drive seek unless specifically requested.

use strict; use warnings; use Win32::OLE qw(in); my $objWMIService = Win32::OLE->GetObject("winmgmts:{impersonationLeve +l=impersonate,(security)}//."); die "Error" unless $objWMIService; my $wmiDiskDrives = $objWMIService->ExecQuery("SELECT Caption, DeviceI +D, InterfaceType FROM Win32_DiskDrive"); print "Device Caption -> InterfaceType -> Drive Letter\n"; print "=" x 60 . "\n"; foreach my $wmiDiskDrive ( in( $wmiDiskDrives ) ) { my $deviceID=$wmiDiskDrive->{DeviceId}; $deviceID=~s/\\/\\\\/sg; my $map=qq|ASSOCIATORS OF {Win32_DiskDrive.DeviceID="$deviceID"} W +HERE AssocClass = Win32_DiskDriveToDiskPartition|; #print "$map\n"; my $wmipartitions = $objWMIService->ExecQuery($map); foreach my $wmipartition ( in( $wmipartitions ) ) { my $deviceID=$wmipartition->{DeviceId}; my $map=qq|ASSOCIATORS OF {Win32_DiskPartition.DeviceID="$devi +ceID"} WHERE AssocClass = Win32_LogicalDiskToPartition|; #print "\t$map\n"; my $wmiLogicalDisks = $objWMIService->ExecQuery($map); foreach my $wmiLogicalDisk ( in( $wmiLogicalDisks ) ) { my $drive=$wmiLogicalDisk->{DeviceId}; print join(" -> ", $wmiDiskDrive->{Caption}, $wmiDisk +Drive->{InterfaceType} , $wmiLogicalDisk->{DeviceId}); print "\n"; } } }

-------------------------------
by me
http://www.basgetti.com
http://www.kidlins.com


In reply to Is a drive USB, IDE or SCSI? by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.