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:?


Perl

Avatar of undefined
Last Comment
sunilbains

8/22/2022 - Mon
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
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?
sunilbains

ASKER
SO that means, we cannot map and unmap drive in the same Script?.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
sunilbains

ASKER
#!/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..
sunilbains

ASKER
Sorry  M = U

Adam314

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sunilbains

ASKER
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
Adam314

You got all of that from the perl script, or from the command line?  
sunilbains

ASKER
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Suhas .

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

sunilbains

ASKER
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
Suhas .

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Suhas .

sunilbains,

Did you get a chance to try the above comment? or need any further suggestions?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sunilbains

ASKER
Thanks All for your Contributions.