Scheduling Batch File as Event

J

Jenny

I'm attempting to get a batch file I have created (that
copies files from 1 directory to another directory by
stopping/restarting services that lock those files) to run
as a scheduled task. The batch file runs perfectly when I
attempt to run it manually, but when I try to run it as a
scheduled event, it stops after executing the "remove
directory" command. The commands I'm using are pretty
simple:

@Echo Off

Net Stop "Service Name1"

Net Stop "Service Name2"

Net Stop "Service Name3"

rd "D:\Main Directory\file folder\files\" /q/s
xcopy "M:" "D:\Main Directory\file
folder\files\" /e/q/h/y/r/i


Net Start "Service Name3"

Net Start "Service Name2"

Net Start "Service Name1"


I've checked and rechecked to ensure I'm using the
administrative user/password when scheduling the event,
but am still not having any luck. The directory gets
removed just fine, but the file copying doesn't happen at
all. Any ideas why this may be happening and/or possible
solutions would be greatly appreciated! :)
 
R

Ricardo M. Urbano - W2K/NT4 MVP

Jenny said:
I'm attempting to get a batch file I have created (that
copies files from 1 directory to another directory by
stopping/restarting services that lock those files) to run
as a scheduled task. The batch file runs perfectly when I
attempt to run it manually, but when I try to run it as a
scheduled event, it stops after executing the "remove
directory" command. The commands I'm using are pretty
simple:

@Echo Off

Net Stop "Service Name1"

Net Stop "Service Name2"

Net Stop "Service Name3"

rd "D:\Main Directory\file folder\files\" /q/s
xcopy "M:" "D:\Main Directory\file
folder\files\" /e/q/h/y/r/i

Net Start "Service Name3"

Net Start "Service Name2"

Net Start "Service Name1"

I've checked and rechecked to ensure I'm using the
administrative user/password when scheduling the event,
but am still not having any luck. The directory gets
removed just fine, but the file copying doesn't happen at
all. Any ideas why this may be happening and/or possible
solutions would be greatly appreciated! :)

Jenny, schedule 'cmd /k' to run interactively with the same credentials
you are using for your script. Schedule it for a couple of minutes in
the future. A new command prompt should open up in the environment and
context that your script will run. Ron the script from this new command
prompt environment and you will be able to see what is going on,
including error messages.

Most likely, the M: drive is not mapped in the environment. Either map
it in the script, or use the UNC path equivalent. I almost always find
using UNC paths to be preferable.

GL!
 
J

Jenny

Thank you! I should've known it would be something
simple. Using the UNC path instead of the mapped drive
actually solved the problem. Thanks again!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top