NAME
Win32::NetName - A more universal way of obtaining the UNC names of local paths
SYNOPSIS
use Win32::NetName qw( GetUniversalName GetLocalName );
use Win32::Lanman;
if( GetUniversalName( my $unc, "c:/my/local/path/to/my/file" ) ){
print $unc; # something like \\SERVER\share\path\to\file
}else{
print Win32::Lanman::GetLastError();
# If there is no WNET error it may just be that there aren't any shares
}
if( GetLocalName( my $local, "\\\\server\\share\\path\\to\\file" ) ){
print $local; # something like C:\my\local\path\to\file
# If there is no WNET error it may just be that there isn't a local path
}else{
print Win32::Lanman::GetLastError();
}
...
DESCRIPTION
The windows WNet API has a function, WNetGetUniversalName that takes a drive-based path for a network resource and returns an information structure that contains a more universal form of the name ie. a UNC path of the form \\SERVER\share\path\to\file.
However, this only works with networked drives that have been mapped to the local machine. It totally ignores shared folders on the local machine.
This module exports two functions, GetUniversalName and GetLocalName.
$success = GetUniversalName( $unc_name, $local_name );
GetUniversalName tries to find a UNC name for a local path. The UNC name is returned in $_[0]. If the drive of the path is local then it enumerates the shared folders on the machine. If it is a network path then it runs the WNetGetUniversalName API function.
$success = GetLocalName( $local_name, $unc_name );
GetLocalName tries to find the local path of a UNC name. If the node name of the UNC name is the local machine then it enumerates the shared folders on the machine. If it is any other machine then it enumerates through the used drive letters to find a match.
The module also contains but does not export;
$success = GetUniversalPaths( \@paths, $local_name );
On success, returns an array in $_[0] of UNC names of the local path (since a local path can be made available from more than one shared folder in its path or the same folder can be shared with multiple names).
$success = GetDiskShares( \@shares, [ $node ] );
On success, returns an array in $_[0] of NET_SHARE_INFO hashes. Unless $node is provided then the name of the local machine is used.
SEE ALSO
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/windows_networking_functions.asp
BUGS
Please report them!
Currently paths are case sensitive.
AUTHOR
Mark Southern (msouthern@exsar.com)
COPYRIGHT
Copyright (c) 2003, ExSAR Corporation. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 212:
You forgot a '=back' before '=head1'