in reply to Is a drive USB, IDE or SCSI?

Hello. After reading up on MSDN, i wrote the following little snippet that performs what you wish. Enjoy!

use strict; use warnings; use Win32::OLE qw(in); my $objWMIService = Win32::OLE->GetObject("winmgmts:{impersonationLeve +l=impersonate,(security)}//."); die "Error" unless $objWMIService; my $colDisks = $objWMIService->ExecQuery("Select * from Win32_DiskDriv +e"); print "Device Caption -> InterfaceType -> DeviceId\n"; print "=" x 60 . "\n"; foreach my $obj ( in( $colDisks ) ) { print join(" -> ", $obj->{Caption}, $obj->{InterfaceType} , $obj-> +{DeviceId}); print "\n"; }

On my machine, it produces the following:

Device Caption -> InterfaceType -> DeviceId ============================================================ WDC WD400BB-00CLB0 -> IDE -> \\.\PHYSICALDRIVE0 WDC WD800JB-00JJA0 -> IDE -> \\.\PHYSICALDRIVE1

Update: minor edit.

Replies are listed 'Best First'.
Re^2: Is a drive USB, IDE or SCSI?
by slloyd (Hermit) on Dec 03, 2005 at 15:01 UTC
      Well, with all the respect, the above code i wrote performs exactly what you indicated in your first post. Should you already had accomplished the very task you were asking for, what was the point of even starting this node? Why didn't you post your code upfront, so the rest of us can work on it rather than having to go through MSDN and come up with something from scratch?

      As for your question, it appears you are confusing some fundamentals here. The physical drive is associated with an InterfaceType, and not the partition. This is what is getting listed here.

        Actually, I did not have it figured out when I posted this node but after trying a bunch of things in WMI I was able to get that far... My end goal is to write a subroutine that accepts a drive letter and returns the InterfaceType (USB, IDE, SCSI) of the partition the drive is on.

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