arkamedis21 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am having trouble using GetUNCName() from Win32::NetResource module. I have directory called

"D:\WIPData"

, and

"T:\temp"

shared on my local machine. I am trying to get the UNC names for them in the format

\\machine_name\share_name

using GetUNCName, and it is barfing for some weird reason. Please let me know if I am using this subroutine the right way, or if there is another way using perl, or some windows system command which might get me the same information.

my @oth_paths = ("T:\\temp", "D:\\WIPdata"); map { my $outpath; print "in_UNC : $_ \n"; Win32::NetResource::GetUNCName ( $outpath , "$_"); print "out_UNC : $outpath \n"; } (@oth_paths);


Thanks

Replies are listed 'Best First'.
Re: Win32:NetResource problem
by Rex(Wrecks) (Curate) on Aug 08, 2002 at 18:07 UTC
    Put a use Net::Resource ; at the top of your code.

    Doing that and using your code worked for me.

    Now this might not be doing what you think. What it will do, is tell you the UNC path of any of your mapped drives, similar to typing net use at the command line. It will not expand your local shares into a UNC path!

    From the NetResource doc:
    Enumerating all resources on a particular host is done like this
    # # This example displays all the share points exported by the local # host. # use strict; use Win32::NetResource qw(:DEFAULT GetSharedResources GetError); if (GetSharedResources(my $resources, RESOURCETYPE_DISK,{ RemoteName = +> "\\\\" . Win32::NodeName() })) { foreach my $href (@$resources) { print "-----\n"; foreach(keys %$href) { print "$_: $href->{$_}\n"; } } }


    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      i do have a

      use Win32::NetResource;

      on top of my code. The touble is that the GetUNCName() works for mapped network drives, just not for local shares for some reason.

Re: Win32:NetResource problem
by Marza (Vicar) on Aug 08, 2002 at 18:14 UTC

    Are you trying to get the UNC for mounted shares? I don't think it works for shares on your system. I tried getting the UNC for a local share. Nothing. Then I did externals; works fine.

    use strict; use warnings; use diagnostics; use Win32::NetResource; my @oth_paths = ("J:\\activeperl", "R:\\McAfee"); map { my $outpath; print "in_UNC : $_ \n"; Win32::NetResource::GetUNCName ( $outpath , $_); print "out_UNC : $outpath \n"; } (@oth_paths);

    Output:

    Trying to get a local and an external share: D:\Sysad-perl\scripts\Reports\AntiVirus Status\TaskScheduler>prob in_UNC : D:\Public out_UNC : in_UNC : R:\McAfee out_UNC : \\Public\Depot\McAfee Getting two external shares: D:\Sysad-perl\scripts\Reports\AntiVirus Status\TaskScheduler>prob in_UNC : J:\activeperl out_UNC : \\Synnac2\pctools\activeperl in_UNC : R:\McAfee out_UNC : \\Public\Depot\McAfee
      Yes, I am trying the GetUNCName() for local shares. Is there any other way to get the local share information through any other perl module, or windows system commands.

      Thanks.
        From the Win32::NetResource docs...
        use strict; use Win32::NetResource qw(:DEFAULT GetSharedResources GetError); if (GetSharedResources(my $resources, RESOURCETYPE_ANY, { RemoteName => "\\\\" . Win32::NodeName() })) { foreach my $href (@$resources) { print "-----\n"; foreach(keys %$href) { print "$_: $href->{$_}\n"; } } }

        is this what you are looking for?

        -Waswas
Re: Win32:NetResource problem
by fruiture (Curate) on Aug 08, 2002 at 18:26 UTC

    Off Topic, but: please, do NOT use map() in void context, use a foreach loop, thanks!

    --
    http://fruiture.de