Win32::NetName - A more universal way of obtaining the UNC names of local paths


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 


        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


        print Win32::Lanman::GetLastError();




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.




Please report them!

Currently paths are case sensitive.


Mark Southern (


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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 228:

You forgot a '=back' before '=head1'