Programmer's Cookbook

Recipes for the practical programmer

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.



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

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?