|
Win32::NetResource - manage network resources in perl |
Win32::NetResource - manage network resources in perl
use Win32::NetResource;
$ShareInfo = {
'path' => "C:\\MyShareDir",
'netname' => "MyShare",
'remark' => "It is good to share",
'passwd' => "",
'current-users' =>0,
'permissions' => 0,
'maxusers' => -1,
'type' => 0,
};
Win32::NetResource::NetShareAdd( $ShareInfo,$parm )
or die "unable to add share";
This module offers control over the network resources of Win32.Disks, printers etc can be shared over a network.
There are two main data types required to control network resources. In Perl these are represented by hash types.
KEY VALUE
'Scope' => Scope of an Enumeration
RESOURCE_CONNECTED,
RESOURCE_GLOBALNET,
RESOURCE_REMEMBERED.
'Type' => The type of resource to Enum
RESOURCETYPE_ANY All resources
RESOURCETYPE_DISK Disk resources
RESOURCETYPE_PRINT Print resources
'DisplayType' => The way the resource should be displayed.
RESOURCEDISPLAYTYPE_DOMAIN
The object should be displayed as a domain.
RESOURCEDISPLAYTYPE_GENERIC
The method used to display the object does not matter.
RESOURCEDISPLAYTYPE_SERVER
The object should be displayed as a server.
RESOURCEDISPLAYTYPE_SHARE
The object should be displayed as a sharepoint.
'Usage' => Specifies the Resources usage:
RESOURCEUSAGE_CONNECTABLE
RESOURCEUSAGE_CONTAINER.
'LocalName' => Name of the local device the resource is
connected to.
'RemoteName' => The network name of the resource.
'Comment' => A string comment.
'Provider' => Name of the provider of the resource.
KEY VALUE
'netname' => Name of the share.
'type' => type of share.
'remark' => A string comment.
'permissions' => Permissions value
'maxusers' => the max # of users.
'current-users' => the current # of users.
'path' => The path of the share.
'passwd' => A password if one is req'd
All of the functions return FALSE (0) if they fail.
GetSharedResources(\@Resources,dwType)The return value indicates whether there was an error in accessing any of the shared resources. All the shared resources that were encountered (until the point of an error, if any) are pushed into @Resources as references to %NETRESOURCE hashes. See example below.
AddConnection(\%NETRESOURCE,$Password,$UserName,$Connection)CancelConnection($Name,$Connection,$Force)WNetGetLastError($ErrorCode,$Description,$Name)
$servername is optional for all the calls below. (if not given the local machine is assumed.)
#
# This example displays all the share points in the entire
# visible part of the network.
#
use strict;
use Win32::NetResource qw(:DEFAULT GetSharedResources GetError);
my $resources = [];
unless(GetSharedResources($resources, RESOURCETYPE_ANY)) {
my $err = undef;
GetError($err);
warn Win32::FormatMessage($err);
}
foreach my $href (@$resources) {
next if ($$href{DisplayType} != RESOURCEDISPLAYTYPE_SHARE);
print "-----\n";
foreach( keys %$href){
print "$_: $href->{$_}\n";
}
}
Jesse Dougherty for Hip Communications.
Additional general cleanups and bug fixes by Gurusamy Sarathy <gsar@activestate.com>.
|
Win32::NetResource - manage network resources in perl |