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.

In reply to Re: Disconnecting from a network drive by joealba
in thread Disconnecting from a network drive by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.