Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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"; }

Replies are listed 'Best First'.
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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-11-30 05:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found