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";
}