Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Disconnecting from a network drive

by Anonymous Monk
on Jun 03, 2002 at 14:02 UTC ( #171238=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I have the following code that maps a remote drive to the letter E. I first need to check to see if this drive letter "E" is already in use, and if so I need to disconnect it and re-map with the follwing code... Any suggestions?
use strict; use Win32::NetResource; print "Mapping drives from .ini file..."; my %NetResource = ( LocalName => "E:", RemoteName => "\\\\Srvbuild\\E" ); my $User = ""; my $Password = ""; if ( Win32::NetResource::AddConnection( \%NetResource, $Password, +$User, 0)) { print "Done\n"; }
Thanks!

Comment on Disconnecting from a network drive
Download Code
Re: Disconnecting from a network drive
by joealba (Hermit) on Jun 03, 2002 at 15:09 UTC
    Win32::GetNextAvailDrive() is a good start, unless you really need to mount the E: drive. Mounting a specific letter would probably be bad form if more than one machine is using ths script, especially when you're using such a low letter.

    THANKS SO MUCH FOR THIS CODE BIT! I've wanted this for a while, but never had the motivation to find it! Now I'll never have to put in my password 10 times each time I log in using Win2K!

    Update: The AddConnection() will fail if the drive letter is already used. So, you can do the ol' trial-and-error check at least to see if it's in use. Disconnecting may be tougher, though. I can't find anything on that so far.

    Update2: Duh.. It was right in front of my face.

    From perldoc Win32::NetResource:
    CancelConnection($Name,$Connection,$Force) Cancels a connection to a network resource connected to local device $ +name. $Connection is either 1 - persistent connection or 0, non-pers +istent.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://171238]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2015-07-05 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls