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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |