slloyd has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to modify this Perl script so it does not try to access the floppy drive every time it is run?
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|; my $wmipartitions = $objWMIService->ExecQuery($map); foreach my $wmipartition ( in( $wmipartitions ) ) { my $deviceID=$wmipartition->{DeviceId}; print "$deviceID\n"; my $map=qq|ASSOCIATORS OF {Win32_DiskPartition.DeviceID="$devi +ceID"} WHERE AssocClass = Win32_LogicalDiskToPartition|; 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

Replies are listed 'Best First'.
Re: Floppy Drive Problems
by NetWallah (Canon) on Dec 04, 2005 at 08:20 UTC
    In your "foreach my $wmiDiskDrive" loop, first check for
    $wmiDiskDrive->{MediaType}
    to be the type of disk you expect:
    From MSDN:

    MediaType

    Data type: string
    Access type: Read-only

    Type of media used or accessed by this device. Values are:

    "Removable media"
    "Fixed hard disk"
    "Unknown"

         You're just jealous cause the voices are only talking to me.

         No trees were killed in the sending of this message.    However, a large number of electrons were terribly inconvenienced.

      Excellent idea but it didn't work. Anytime Win32_LogicalDiskToPartition is called it must do a select * because it seeks the floppy drive ever time, even if you are not looking for the floppy.

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

        Hmm - you are absolutely right.(++)

        I did try an alternative method - to access Win32_MappedLogicalDisk, to get to the same info, but that does not seem to work at all (Win XP). There is no indication of any error, and it returns zero logical drives.

        Sounds like you need to waste more time talking to M$ tech support, since Google provides no clues on this one.

             You're just jealous cause the voices are only talking to me.

             No trees were killed in the sending of this message.    However, a large number of electrons were terribly inconvenienced.