Link to home
Start Free TrialLog in
Avatar of sunilbains
sunilbains

asked on

Perl script to Unmap drive

Hi ,
Iam using this command inside my perl script.
system("net use M: \\\\Stmroot\\data\\Essoc\\Legal&Comp\\LC_GMP\\reports\\bo");
...
script code
..
system("net use M: /DELETE ");
Iam getting Following error:
Network Drive is Already In use

Couldnot find network path


So iam able to Copy files from M drive. But Why iam not able to Disconnect it.
Any Syntax error:?


Avatar of Adam314
Adam314

You can't unmap the drive if anything is using anything on that drive.  You can use the handle program to find out what is using that drive.  It doesn't come with windows, but is a free download:
http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
Avatar of FishMonger
Are you doing anything in your script that creates a connection the M drive, such as opening a file or directory handle?  If so, are you closing that connection prior to deleting the drive mapping?
Avatar of sunilbains

ASKER

SO that means, we cannot map and unmap drive in the same Script?.
#!/usr/bin/perl
use File::Copy;
use strict;
 system("net use M: \\\\Stmroot\\data\\Essoc\\Legal&Comp\\LC_GMP\\reports\\bo");
open(MYDATA, "D:/1.txt") or die("Error: cannot open file 'gdmp_pdf_file_list.out': $!\n");
my $line;
while( $line = <MYDATA> ){
  chomp($line);
  print "$line\n";
  if ( -e "U:$line" )
 {
    copy ("U:$line","D:/x/y/z) or warn "Could not copy $line: $!\n";
 }
  else
  {
    print "File $line Does not Exist\n";
  }
}
close MYDATA;
system("erase \\\\nldn1062pww\\compmonitor\\GDMP\\GSS\\Script\\gdmp_pdf_file_list.out");
system("net use M: /DELETE ");

I just need to close M after files are copied..
Sorry  M = U

I don't see anything that should be causing a problem.
If you try to run the net use U: /DELETE after your script finishes, does it work?

Try sleeping for a few seconds before attempting to unmap the drive, in case windows does any caching.

...
system("erase ...");
sleep(10);
system("net use U: /DELETE");

Open in new window

Hi Adam,
 Got Following Err after putting 10 seconds
system error 85 has occurred.
The local device name is already in use.
The network connection could not be found.
More help is available by typing NET HELPMSG 2250.

Iam also not able to unmap from DOS.

Script is Running from Schduler
You got all of that from the perl script, or from the command line?  
From Perl Script..

Also when i tried to unmap  it from DOS , I got same error
The network connection could not be found.
More help is available by typing NET HELPMSG 2250.
Hello sunilbains,
Please try the attached code to delete the mapped drive and map it again.

Regards,
suhasbharadwaj
use strict;
system("net use \/d U:"); # to delete a mapped drive
system("net use U: \\\\Stmroot\\data\\Essoc\\Legal&Comp\\LC_GMP\\reports\\bo"); 

Open in new window

Hi Suhas,
 I tried but same error;
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.


System error 85 has occurred.


The local device name is already in use.
ASKER CERTIFIED SOLUTION
Avatar of Suhas .
Suhas .
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sunilbains,

Did you get a chance to try the above comment? or need any further suggestions?
Thanks All for your Contributions.