dbrock has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a script to read some logfiles of a backup software package... Then enter this data into a Database... These logfiles are located on several windows machines in different domains... Authenticating with different id's... I am currently mapping each of these drives manually then executing my script... I am looking for a way to automate this process... I need a way to map several drives to multipal computers... perhaps using a .ini type file to hold the computernames... I am currently setting a $var manually in my Script...

$map = 'v:\\program files\\veritas\\nt\\data';

then i read the directory into an array remove the . & .. and process the files I need... If any one has some ideas on how i can do this..? dbrock05@comcast.net
  • Comment on Map Drive in Windows (need to authenticate)

Replies are listed 'Best First'.
Re: Map Drive in Windows (need to authenticate)
by tachyon (Chancellor) on Feb 28, 2003 at 12:08 UTC

    Use backtics or system to exec a NET USE.

    NET USE [devicename | *] [\\computername\sharename[\volume] [password +| *]] [/USER:[domainname\]username] [/USER:[dotted domain name\]username] [/USER:[username@dotted domain name] [[/DELETE] | [/PERSISTENT:{YES | NO}]] #!/usr/bin/perl my $drive = 'z:'; my $computername = 'zeus'; my $sharename = 'c$'; my $password = 'password'; my $domain = 'some.domain'; my $user = 'god'; my $persistent = 'no'; my $res = `NET USE $drive \\\\$computername\\$sharename $password /USE +R:$domain\\$user /PERSISTENT:$persistent`; error() unless $res =~ m/The command completed successfully/; sub error { print "Error!\n" and exit }

    You will get a conflict of credential error if you are logged on as administrator and try to use the same username/password (that's windows for you). In this case just don't pass a password and username and it will work.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Thank You... I started experimenting and was on the same track as your example... Darrick...
Re: Map Drive in Windows (need to authenticate)
by blm (Hermit) on Feb 28, 2003 at 12:24 UTC

    Or in the spirit of perl (TIMTOWTDI) here is another way to map a drive in perl.

    use Win32::OLE; use Win32::OLE::Variant; my ($username, $password) = ('Administrator',''); my $network = Win32::OLE->new('WScript.Network') or die('Error creating network object'); $network->MapNetworkDrive('O:','\\\\127.0.0.1\\dev', 0, $username, $password)

    More information on this method can be found here.

      I´m a perl rookie and I search so long for this. Thanks a lot for this and you make(save) my day But how can i disconnect a drive and if it´s in use is it possible to use the next free drive? ms-pasa
Re: Map Drive in Windows (need to authenticate)
by Marza (Vicar) on Feb 28, 2003 at 07:50 UTC

    Take a look at Jenda's FileOp

    The Mapped function has what you need.

    UPDATE:

    DOH!

    To think I changed it to that!

      I think you meant Map(). Mapped() returns the path to which is a drive mapped :-)

      To add to the TIMTOWTDI ... you have also use Win32::AdminMisc or Win32::Lanman.

      Jenda