perlofwisdom has asked for the wisdom of the Perl Monks concerning the following question:
I am using the following command to make the connection (this works OK):
system("net use ${drive} \\\\${server}\\${remote_drv_ltr}\$ ${passwd} /USER:${domain}\\${login}");I cobbled together an 'unmount' routine to disconnect the share before going on to the next server. Retrying the delete command every 2 seconds for up to 30 seconds before giving up (this doesn't work reliably).
while ( system("net use $drive /DELETE") ) { : (I can provide the details if necessary) }
I've fumbled around with Win32::NetResource but can't find a good example of how to get it to map a drive, and later release it. Here's what I've got (which doesn't work at all):
use Win32::NetResource qw(:DEFAULT GetSharedResources GetError AddCo +nnection CancelConnection); my $Domain = 'aaaaaaaa'; my $Account = 'bbbbbbbb'; my $Password = 'cccccccc'; my $Server = 'dddddddd'; my $LocalDrive = 'X:'; my $UserName = '${Domain}\\${Account}'; my $Connection = 0; my $ShareInfo = { 'path' => "C:\\temp", 'netname' => "MyShare", 'remark' => "It is good to share", 'passwd' => "", 'current-users'=> 0, 'permissions' => 0, 'maxusers' => -1, 'type' => 0, }; my %NETRESOURCE = ( 'Scope' => 'RESOURCE_REMEMBERED', 'Type' => 'RESOURCETYPE_DISK', 'DisplayType' => 'RESOURCEDISPLAYTYPE_SHARE', 'Usage' => 'RESOURCEUSAGE_CONTAINER', 'LocalName' => "$LocalDrive", 'RemoteName' => "\\\\$Server\\D\$", 'Provider' => "$Server" ); AddConnection(\%NETRESOURCE,$Password,$UserName,$Connection); # CancelConnection($Name,$Connection,$Force);
I'm sure I'm way off (as evidenced by my lack of results). Do any of you have any constructive suggestions, alternate solutions, or (preferably) some sample code to help me get Win32::NetResource's "AddConnection" and "CancelConnection" to do what I need?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do you Map & Disconnect Network Drives (in Windows)?
by igelkott (Priest) on Mar 25, 2008 at 21:07 UTC | |
by perlofwisdom (Pilgrim) on Mar 26, 2008 at 18:05 UTC | |
Re: How do you Map & Disconnect Network Drives (in Windows)?
by Corion (Patriarch) on Mar 26, 2008 at 07:04 UTC | |
by perlofwisdom (Pilgrim) on Mar 26, 2008 at 13:48 UTC | |
by Corion (Patriarch) on Mar 26, 2008 at 13:55 UTC | |
Re: How do you Map & Disconnect Network Drives (in Windows)?
by Jenda (Abbot) on Mar 26, 2008 at 07:09 UTC | |
by perlofwisdom (Pilgrim) on Mar 26, 2008 at 15:02 UTC | |
by Jenda (Abbot) on Mar 26, 2008 at 21:48 UTC |