Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Connectivity to Windows Share

by gautamparimoo (Beadle)
on Mar 22, 2013 at 06:45 UTC ( #1024882=perlquestion: print w/ replies, xml ) Need Help??
gautamparimoo has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I need to check connectivity to a particular Windows Share. I have tried

1. Net View command but it was for viewing the Network connected resources not particulary shares.

2. The following code i got from Microsoft site
se Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; $computer = "."; $objWMIService = Win32::OLE->GetObject ("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection fai +led.\n"; $colItems = $objWMIService->ExecQuery ("SELECT * FROM Win32_Share","WQL",wbemFlagReturnImmediately | wbe +mFlagForwardOnly); foreach my $objItem (in $colItems) { print "Access Mask: $objItem->{AccessMask}\n"; print "Allow Maximum: $objItem->{AllowMaximum}\n"; print "Caption: $objItem->{Caption}\n"; print "Description: $objItem->{Description}\n"; print "Install Date: $objItem->{InstallDate}\n"; print "Maximum Allowed: $objItem->{MaximumAllowed}\n"; print "Name: $objItem->{Name}\n"; print "Path: $objItem->{Path}\n"; print "Status: $objItem->{Status}\n"; print "Type: $objItem->{Type}\n"; print "\n"; }

But It just specifies the windows share as $IPC without showing any IP or computer name of the share.

Pls tell how to check connectivity to a windows share ?

I found this script on Roth consulting site but wheb is run it shows Access Denied for path of $IPC even though I am Administrator. What could be the reason? The script is below

use Win32::Lanman; if( scalar @ARGV ) { @Machines = @ARGV; } else { push( @Machines, Win32::NodeName() ); } foreach my $Machine ( @Machines ) { my @List; $Machine = "\\\\" . $Machine; $Machine =~ s/\//\\/; $Machine =~ s/^\\{2,}/\\\\/; print "\nShare list for '$Machine'\n"; if( Win32::Lanman::NetShareEnum( $Machine, \@List ) ) { my $iCount = 0; printf( "\n % 4s %- 16s %- 20s %s\n %- 4s %- 16s %- 20s %s\n +", "Num", "Share Name", "Remark", "Path", "-" x 4, "-" x 16, "-" x 20, "-" x 30 ); foreach my $Share ( @List ) { my( $Remark, $Path, $NetName ); $NetName = $Share->{netname}; if( "" ne $Share->{remark} ) { $Remark = "($Share->{remark})"; } if( "" ne $Share->{path} ) { $Path = $Share->{path}; } else { $Path = "Access Denied"; } printf( " % 3d) %- 16s %- 20s %s\n", ++$iCount, $NetName, + $Remark, $Path ); } } else { print "...not available : " . Win32::FormatMessage( Win32::Lanman +::GetLastError() ) . "\n"; } print "\n"; }

Comment on Connectivity to Windows Share
Select or Download Code
Re: Connectivity to Windows Share
by Anonymous Monk on Mar 22, 2013 at 07:25 UTC

    Pls tell how to check connectivity to a windows share ?

    Ask microsoft, specifically msdn, specifically check WMI documentation , if it is possible to accomplish the answer will be found there

    See also DBD::WMI

Re: Connectivity to Windows Share
by hdb (Prior) on Mar 22, 2013 at 09:14 UTC

    Not quite sure what you are looking for. The current shares can be seen via the "net use" command, or in code:

    my $shares = `net use`; print $shares;

      Agreed. Perl is awesome, but it isn't always the best option by itself. Often times it is best used as a glue language, making smart use of exiting tools that can already solve the problem.

      Christopher Cashell

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024882]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (26)
As of 2015-07-01 13:49 GMT
Find Nodes?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?

    Results (816 votes), past polls