Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
How do you Map & Disconnect Network Drives (in Windows)?by perlofwisdom (Pilgrim) |
on Mar 25, 2008 at 20:52 UTC ( [id://676238]=perlquestion: print w/replies, xml ) | Need Help?? |
perlofwisdom has asked for the wisdom of the Perl Monks concerning the following question:
I have a need to connect to the C$ and D$ shares on various windows servers. I want to loop through the servers one at a time, and re-use the same local drive letter for the share. I'm having trouble getting the disconnect subroutine to delete the share before it tries to connect to the next server.
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).
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):
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?
Back to
Seekers of Perl Wisdom
|
|