Re: Network drives not disconnecting when running scheduled tasks

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thanks again for your reply.

I'm not disagreeing that batch files can map drives, I just don't feel that
it is necessarily the right approach for my script - it will add an extra
layer of complexity to what I am trying to acheive. I also don't feel that
it will resolve the underlying issue that I am experiencing.

If you would like to recreate the problem that I have (but beware that the
only method found so far for removing the "ghost" mapped drive is a reboot!)
cut and past the following into a vbscript:

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"
wscript.echo "Test echo"

and run it as a scheduled task - using wscript. The script will try to echo
to the screen, but as it is running as a scheduled task the echo will not be
visable, and so the script will hang. Then stop the scheduled task by right
clicking and selecting end task.

If you then try to work with the mapped drive via e.g. a batch file, it
won't be possible to remove it, or re-map it. As I said in a previous post,
the only way I have found to prove the existance of the drive is to run "dir
e:" from within a batch file run as a scheduled task - piping the output to a
text file.




"Pegasus (MVP)" wrote:

> You should add some basic reporting tools to the mapping
> part of your batch file so that you can see what's going on.
> Scheduled batch files ***can*** map files - if you can't see
> them then it's due to a coding or permission problem. Try
> this:
>
> Line1 @echo off
> Line2 echo %date% %time% Start of task > c:\test.log
> Line3 echo User=%UserName%, Path=%path% >> c:\test.log
> Line4 %SystemRoot%\System32\net.exe use x: \\SomeServer\SomeShare
> 1>>c:\test.log 2>c:\test.err
> Line5 echo ErrorLevel of net.exe=%ErrorLevel% >> c:\test.log
> Line6 echo %date% %time% End of task >> c:\test.log
>
> Now have a look at the two log files and all will become clear.
>
>
> "Jo Winchester" <JoWinchester@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:A64B4660-DE42-442F-B9D3-AE05E9C07F23@xxxxxxxxxxxxxxxx
> > Thanks for your reply.
> >
> > However, I cannot map to a UNC path, as the script needs to use a drive
> > letter i.e. "lcd e:".
> >
> > Also, I have tried expermenting with a batch file - and running it as a
> > scheduled tasks. Even running commands by this method does not allow me
> to
> > unmap the "ghost" drive mapping. I created a batch file that would output
> > the results of a "net use" command to a text file - but no drives show.
> The
> > only evidence I can get that the drive exists is if I add a line to the
> batch
> > file that does "dir e:" and outputs to a text file. This will list the
> files
> > that are in the remote location.
> >
> > Having said all of this, I have tried your suggestion of "net use x: /del"
> > at the end of my batch file, but it does not recognise that the drive is
> > mapped.
> >
> > Finally, yes I agree I could attempt to map the drives simply by using a
> > batch file outside a vbscript - however the script does a lot more than
> map a
> > drive and run an FTP job - it includes a lot of error checking, sends
> > e-mails, confirms servers are available. Also, the script reads a control
> > file so that it can carry out multiple file transfers - each time the
> script
> > loops, a different drive is mapped - so to try and control this through a
> > batch file would be very difficult.
> >
> > Jo
> >
> > "Pegasus (MVP)" wrote:
> >
> > >
> > > "Jo Winchester" <JoWinchester@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message
> > > news:8F4F1735-2B53-4B62-95D6-4EF87285914C@xxxxxxxxxxxxxxxx
> > > > I have an issue that I am trying to run a vbscript, that automatically
> > > runs
> > > > an FTP job. The script worked well in testing, until I tried to run
> it as
> > > a
> > > > scheduled task.
> > > > An integral part of the script is to map a network drive, that is then
> > > > utililised by an FTP task ("lcd e:\"). The problem is that if the
> script
> > > > fails, then the mapped drive is remembered by task scheduler, but it
> > > cannot
> > > > be viewed by any of the normal methods e.g. net use, Windows Explorer
> or
> > > > subst.
> > > >
> > > > I have found a number of postings with people having the same issues,
> but
> > > am
> > > > yet to find a solution.
> > > >
> > > > Any help appreciated.
> > >
> > > The usual cure is not to map drives by scheduled tasks but use
> > > UNC coding instead.
> > >
> > > Another simple cure is to control the scheduled task tightly
> > > and to check at its end if the problem drive is still mapped.
> > > This can be done by embedding the script in a batch file.
> > > The last instruction of the batch file could be
> > >
> > > net use x: /del
> > >
> > > which would execute even if the script failed.
> > >
> > > A third way would be to code the whole thing as a batch
> > > file like so:
> > >
> > > @echo off
> > > set script=c:\script.scr
> > > set site=www.yoursite.com
> > > set account=Jack
> > > set password=Jill
> > >
> > > echo %account%>%script%
> > > echo %password%>>%script%
> > > echo binary>>%script%
> > > echo get SomeFile.txt >>%script%
> > > echo quit >>%script%
> > >
> > > net use x: \\SomeServer\SomeShare
> > > cd /d x:\SomeFolder
> > > ftp -s:%script% %site%
> > > net use x: /del
> > >
> > >
> > >
>
>
>
.



Relevant Pages

  • Re: troubleshoot a script
    ... I see you use the memberOf attribute. ... ' map appropriate drives. ... The part of the script that will not work for the 3 ...
    (microsoft.public.scripting.vbscript)
  • Unable to remove remembered drives
    ... The script is completely finished and works perfectly if I ... It turned out that it couldn't map the drive for some ... appears I cant remove these remembered drives, ... Set fso = Createobject ...
    (microsoft.public.scripting.vbscript)
  • Drive Mapping Script Not working
    ... I have a script that maps drives based on a machines name here is a sample ... net use and map the share correctly net use reports the share to already be ...
    (microsoft.public.windows.server.scripting)
  • Re: troubleshoot a script
    ... I run a batch file to delete mapped drives and map to ... The part of the script that will not work for the 3 ... THIS IS THE BATCH FILE THAT IS LAUNCED UNDER THE USERS PROFILE ...
    (microsoft.public.scripting.vbscript)
  • Re: User Independent Mapped Drive
    ... OU that runs a batch file to map the drives. ... server of where they're from. ... script, ...
    (microsoft.public.windows.server.networking)