Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: USB Drive Letter Assignment in Win32

by traveler (Parson)
on Jun 06, 2004 at 22:16 UTC ( #361819=note: print w/replies, xml ) Need Help??

in reply to Re: USB Drive Letter Assignment in Win32
in thread USB Drive Letter Assignment in Win32

Actually, after long consideration, I suppose not. I could look for it every time, if it is not too long a process. I need the data on the drive available at the very start of the login process so if I could find it, it would be alright. Any idea how to find a thumb drive?
  • Comment on Re^2: USB Drive Letter Assignment in Win32

Replies are listed 'Best First'.
Re^3: USB Drive Letter Assignment in Win32
by ambrus (Abbot) on Jun 06, 2004 at 22:28 UTC

    Any idea how to find a thumb drive?

    You could try putting a file of certain name on the drive and search for that in the root of every drive. Else, you could just find the last valid drive letter, and you have some chance that it is the usb device. Or else you could just find the drive with the smallest capacity (excuding floppies), but that may fail to work later if usb devices get cheaper.

      Or create a description file for each drive in its root. And have your scripts at startup that need particular drives scan these files. Or have a first run script that updates an index file so your scripts just read the index to find a resource. This sounds familiar????

      "No matter where you go, there you are." BB
Re^3: USB Drive Letter Assignment in Win32
by Zero_Flop (Pilgrim) on Jun 07, 2004 at 18:38 UTC
    Sorry for the late responce--

    Give the drive a Label "USBDrive" then...
    use Win32::AdminMisc; %Info = Win32::AdminMisc::GetVolume($drive); print "Drive label is $Info{Volume}\n";
    Cycle through all the attached drives and then you will be able to find the drive you are looking for.
    See the doc for complete info:
      I installed the ppd and then ran this code. Perl whined about no GetVolume and I could not find it either. I have version 2003.07.14


        From the information at the Roth site, you will need probably two calls, 
        GetDrives to get an array of all drives and GetVolumeInfo. (sorry not GetVolume)
        This will return an array of drive roots. If no parameters are passed then the list will be all drives 
        (cdroms, floppy, fixed, net, etc.).
        If you specify $Type the list will only contain drive roots
         that are of the specified type.
        The types are:
        @Drives = Win32::AdminMisc::GetDrives();
        @CDROMs = Win32::AdminMisc::GetDrives( DRIVE_CDROM );
        nothing if unsuccessful
        array if successful
        GetVolumeInfo( $Drive )
        This will return a hash of drive volume information for the $Drive drive. 
        $Drive must be a root directory such as "c:\\" or "X:/". $Drive may be a UNC.
        Returned keys are:
        $Volume...............The volume label for the drive.
        $Serial...............The serial number for the drive (in decimal)
        $MaxFileNameLength....The max number of chars a file name can be for drive.
        SystemFlag...........System flags which can be combination of:
        FS_CASE_IS_PRESERVED....The case of filenames are stored on the disk.
        (for example DOS makes file names uppercase)
        FS_CASE_SENSITIVE ......File system supports case sensitive filenames.
        FS_UNICODE_STORED_ON_DISK...File system supports unicode filenames.
        FS_PERSISTENT_ACLS......File System saves and enforces access control
        lists (aka file permissions)
        FS_FILE_COMPRESSION ....File system supports file based compression.
        FS_VOL_IS_COMPRESSED....Volume is compressed (as in using DoubleSpace).
        $::ThisPageSystemName.......The name of the format of the drive (eg. NTFS, FAT)
        if( %Volume = Win32::AdminMisc::GetVolume("//server1/c\$") )
            my $Serial = uc( sprintf( "%x", $Volume{Serial} ) );
            $Serial =~ s/(....)(....)/$1-$2/;
            print "The drive is formatted with the $Volume{FileSystemName} format.\n";
            print "The volume serial number is: $Serial\n%quot;;
         hash if successful
         undef if not successful

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://361819]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-06-27 05:18 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (86 votes). Check out past polls.