What do you not understand? The two things from his book worked for me. However, I did remove the $ from the RemoteName assignment.

use Win32::NetResource; use Win32::WinError; use strict; use warnings; my %NetResource = ( LocalName => "R:", RemoteName => "\\\\Public\\Depot" ); print $NetResource{RemoteName}; my $User = ""; my $Password = ""; if ( Win32::NetResource::AddConnection( \%NetResource, $Password, $Use +r, 1) ) { print "Successful!\n"; } else { print NetError(); } sub NetError { my ( $Error, $Text, $Provider, $Result); $Error = Win32::GetLastError(); if( ERROR_EXTENDED_ERROR == $Error ) { Win32::NeResource::WNetGetLastError( $Error, $Text, $Provider +); $Result = "Error $Error: $Text (generated by $Provider)"; } else { $Text = Win32::FormatMessage( $Error ); $Result = "Error $Error: $Text"; } return $Result; }

Keep in mind if the user and password are blank that says to keep it local to the machine you are accessing. If you are accessing a wide open share then you will have no problems. Otherwise, it wants an id and password which is bad since the password is plaintext. But if you are the sole user of the script and people won't see it....

And don't forget that if you use this to disconnect and or allow for finding the share already mounted.


In reply to Re: Using Win32 network shares by Marza
in thread Using Win32 network shares by John M. Dlugosz

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.