[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-win32-admin
Subject:    Re: map a w2k share
From:       "Patrick J. LoPresti" <patl () users ! sourceforge ! net>
Date:       2002-12-20 17:46:24
[Download RAW message or body]

--=-=-=

"Thomas R Wyant_III" <Thomas.R.Wyant-III@usa.dupont.com> writes:

> Have you read the docs that come with ActivePerl? You might want to
> check out Win32::NetResource.

I had not noticed that one; thanks.

You can also use WSH for this.  A sample "map-drive.pl" script is
below.

 - Pat


--=-=-=
Content-Disposition: inline; filename=map-drive.pl
Content-Description: map-drive.pl


use warnings;
use strict;

use Win32::OLE;

sub die_usage () {
    die "Usage: $0 <drive> <share>\n";
}

scalar @ARGV == 2
    or die_usage ();

my ($drive, $share) = @ARGV;

$drive =~ /^[a-z]:$/i
    or die_usage ();

# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);

# Get WshNetwork object.  See
# <http://msdn.microsoft.com/library/en-us/script56/html/wsobjwshnetwork.asp>
my $wsh_network = Win32::OLE->CreateObject ('WScript.Network');

# Remove network drive forcibly, if it is already mapped. See
# <http://msdn.microsoft.com/library/en-us/script56/html/wsmthremovenetworkdrive.asp>
-e "$drive/"
    and $wsh_network->RemoveNetworkDrive ($drive, 1);

# Map network drive.  See
# <http://msdn.microsoft.com/library/en-us/script56/html/wsmthmapnetworkdrive.asp>
$wsh_network->MapNetworkDrive ($drive, $share);

--=-=-=--
_______________________________________________
Perl-Win32-Admin mailing list
Perl-Win32-Admin@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic