in reply to Finding mapped drive data

Googling "Finding drive info with Perl" pointed me to Win32::DriveInfo. Win32::DriveInfo::DrivesInUse() will tell you what drives exist. There are also functions to give you info on each drive, as well as to tell you what drive letters are still available.


Dave

Replies are listed 'Best First'.
Re^2: Finding mapped drive data
by merrymonk (Hermit) on May 06, 2011 at 06:44 UTC
    Thanks for that. I did try the Perl in the link but sadly I did not have the required Win32::DriveInfo.
    However I did use your google search and found a page which explained where the drive letters are in the registry.
    The following Perl gives what I wanted.
    It works for XP but I do not know about other Windows OS
    use strict "vars"; my (%dletters, $return_code, $return_message, $jl); sub drive_letters_find($$$) { ##------------------------------------------------------------------- ## this gets the drive letters and their paths for the current PC # it returns a has where key is drive letter - value is it contents ## ------------------------------------------------------------------ my ($ref_dletters, $ref_return_code, $ref_return_message) = @_; my ($pp, $k, $key, $vals, $CurrVer, %vals); use Win32::Registry; $pp = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Map Net +work Drive MRU\\"; $$ref_return_code = $main::HKEY_CURRENT_USER->Open($pp, $CurrVer); if($$ref_return_code == 1) { $$ref_return_message = 'drive letters found'; $CurrVer->GetValues(\%vals); foreach $k (keys %vals) { $key = $vals{$k}; $ref_dletters->{$$key[0]} = $$key[2]; } } else { $$ref_return_message = "Could not open regsitry $pp\n\n"; } } drive_letters_find(\%dletters, \$return_code, \$return_message); print "\nafter drive_letters_find\nresult code <$return_code> message +<$return_message>\n"; if($return_code == 1) { print "mapped drive letters found\n"; foreach $jl (sort {$a cmp $b} keys %dletters) { print "letter <$jl> path <$dletters{$jl}>\n"; } }