Problem with Win32::FileOp->Disconnect
Problem with Win32::FileOp->Disconnect
am 18.06.2009 10:39:07 von extern.Lars.Oeschey
Hi,
I'm writing a simple network copy script, but fail at disconnecting an
already connected drive. I got this so far:
----------------snip------------------------
use strict;
use warnings;
use Win32::FileOp;
my $user="xx";
my $password="xx";
my $path="\\\\deaudiis0957\\oeschela\$";
my $lettermatch=0;
print "Using User: $user\n";
print "Using Path: $path\n";
print "Checking mapped drives....\n";
my %mapped=Mapped;
while((my $key, my $value) = each(%mapped)) {
print "$value\n";
if (lc($value) eq lc($path)) {
$lettermatch=1;
print "..........Already Mapped!!.........\n";
}
}
if ($lettermatch==1) {
print "Disconnecting $path\n";
Disconnect $path, {persistent=>1,force=>1} or &ConnError;
}
sub ConnError{
my $err=Win32::FormatMessage(Win32::GetLastError());
print $err;
print "Win32Error: $err\n";
exit 1;
}
--------------snip--------------------
when I run it, it finds the mapped drive, but fails on disconnecting it:
Using User: deaudi00\oeschela
Using Path: \\deaudiis0957\oeschela$
Checking mapped drives....
\\DEAUDIIS0957\Oeschela$
...........Already Mapped!!.........
Disconnecting \\deaudiis0957\oeschela$
Diese Netzwerkverbindung ist nicht vorhanden.
Win32Error: Diese Netzwerkverbindung ist nicht vorhanden.
(translated it says "This network connection doesn't exist")
Any ideas what goes wrong here?
Lars
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Problem with Win32::FileOp->Disconnect
am 18.06.2009 11:24:25 von Ramkumar
Hi,
We can also use dos command "net use" using system method to achieve your
below request.
Regards,
Ramkumar,
-----Original Message-----
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Oeschey,
Lars (I/ET-83, extern)
Sent: Thursday, June 18, 2009 2:09 PM
To: activeperl@listserv.ActiveState.com
Subject: Problem with Win32::FileOp->Disconnect
Hi,
I'm writing a simple network copy script, but fail at disconnecting an
already connected drive. I got this so far:
----------------snip------------------------
use strict;
use warnings;
use Win32::FileOp;
my $user="xx";
my $password="xx";
my $path="\\\\deaudiis0957\\oeschela\$";
my $lettermatch=0;
print "Using User: $user\n";
print "Using Path: $path\n";
print "Checking mapped drives....\n";
my %mapped=Mapped;
while((my $key, my $value) = each(%mapped)) {
print "$value\n";
if (lc($value) eq lc($path)) {
$lettermatch=1;
print "..........Already Mapped!!.........\n";
}
}
if ($lettermatch==1) {
print "Disconnecting $path\n";
Disconnect $path, {persistent=>1,force=>1} or &ConnError;
}
sub ConnError{
my $err=Win32::FormatMessage(Win32::GetLastError());
print $err;
print "Win32Error: $err\n";
exit 1;
}
--------------snip--------------------
when I run it, it finds the mapped drive, but fails on disconnecting it:
Using User: deaudi00\oeschela
Using Path: \\deaudiis0957\oeschela$
Checking mapped drives....
\\DEAUDIIS0957\Oeschela$
...........Already Mapped!!.........
Disconnecting \\deaudiis0957\oeschela$
Diese Netzwerkverbindung ist nicht vorhanden.
Win32Error: Diese Netzwerkverbindung ist nicht vorhanden.
(translated it says "This network connection doesn't exist")
Any ideas what goes wrong here?
Lars
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Problem with Win32::FileOp->Disconnect
am 18.06.2009 14:25:09 von Jenda Krynicky
From: "Oeschey, Lars (I/ET-83, extern)"
> I'm writing a simple network copy script, but fail at disconnecting an
> already connected drive. I got this so far:
>
> ----------------snip------------------------
> use strict;
> use warnings;
> use Win32::FileOp;
>
> my $user="xx";
> my $password="xx";
> my $path="\\\\deaudiis0957\\oeschela\$";
> my $lettermatch=0;
>
>
> print "Using User: $user\n";
> print "Using Path: $path\n";
> print "Checking mapped drives....\n";
>
> my %mapped=Mapped;
>
> while((my $key, my $value) = each(%mapped)) {
> print "$value\n";
> if (lc($value) eq lc($path)) {
> $lettermatch=1;
$lettermatch = $key;
> print "..........Already Mapped!!.........\n";
> }
> }
>
> if ($lettermatch==1) {
if ($lettermatch) {
> print "Disconnecting $path\n";
> Disconnect $path, {persistent=>1,force=>1} or &ConnError;
print "Disconnecting $path as $lettermatch\n";
Disconnect $lettermatch, {persistent=>1,force=>1} or &ConnError;
> }
Try to disconnect the drive letter, not the share. I think if you
specify the share, it breaks the connection (the server will no
longer see this computer among the connected ones, no files will be
open etc.), but doesn't remove the drive letter mapping.
Let me know if it helped and I'll update the docs.
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Problem with Win32::FileOp->Disconnect
am 18.06.2009 15:29:20 von extern.Lars.Oeschey
> Try to disconnect the drive letter, not the share. I think if you
> specify the share, it breaks the connection (the server will no
> longer see this computer among the connected ones, no files will be
> open etc.), but doesn't remove the drive letter mapping.
I'm trying to catch both possibilities, that the path is mapped with or
without a letter. I need to remap it with a specific user afterwards,
and as you know Windows coughs loud if it's already connected with
another credential....
A "net use \\server\path /d" works in a Dos-Box, this is essentially
what I would need...
Lars
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs