Sunday, February 12, 2006
Get Shared Windows Network Resources with Perl
The following code can be run on Windows using ActiveState's Perl. It will print data about each shared network resources on the machine.
Sample Output:
See also: Perldoc for Win32::NetResource
use Win32::NetResource qw(:DEFAULT GetSharedResources);
if (GetSharedResources(my $resources, RESOURCETYPE_ANY,
{RemoteName => "\\\\" . Win32::NodeName()}))
{
foreach my $href (@$resources) {
print "-----\n";
foreach (keys %$href) {
print "$_: $href->{$_}\n";
}
}
}
Sample Output:
C:\>perl getresources.pl
-----
LocalName:
Scope: 2
DisplayType: 3
Type: 1
Provider: Microsoft Windows Network
Usage: 1
Comment:
RemoteName: \\RHANSON\outgoing
See also: Perldoc for Win32::NetResource