Batch file help

Associate
Joined
18 Oct 2002
Posts
2,055
Location
Southend-on-Sea
I'm trying to create a small batch file that will copy some files from a Windows 2008 server to a Windows 7 PC. The (very simple) batch file is:

Code:
copy /Y p:\db\file1.DBF c:\db
copy /Y p:\db\file2.DBF c:\db
copy /Y p:\db\file3.DBF c:\db

echo Date.%Date% >>c:\db\log.txt
echo Time.%Time% >>c:\db\log.txt

When I run this directly from the command prompt on the Windows 7 PC, all the files get copied and the log.txt is updated with the time and date of the run.

However, when trying to schedule this via Scheduled Tasks on the same PC, the batch file runs but the files are not copied over, although the time and date are being updated in log.txt.

I've got the scheduled task set to run as an admin and permissions seem fine, but it just won't work through scheduled tasks.

I've googled and from what I can tell the above code should work but it clearly isn't. Can anyone advise on what I might be missing here?

Thanks
 
From a quick google on the issue:

1) Make sure that the task is set to "configure for Windows Vista or Windows 2008" on the first page of the task properties (under the "general" tab)
2) Make sure that the task is set to "start in" the folder that contains the batch file: open the task properties, click on the "actions" tab, click on the action and then the "edit" button at the bottom. In the "Edit Action" Window there is a field for "start in (optional)" that you set to the path to the batch file.
3) Make sure that the task is running as an account that has explicit "Full access" permissions to all these things: The .bat file itself, the folder containing the .bat file, and the target files/folders that are affected by the .bat script. Inherited permissions didn't seem to work for me.
4) Make sure that the account running the task is a member of the local "administrators" group for this machine
5) Make sure that the task is set to "run whether logged on or not"
6) The Task should run successfully with expected output when you right-click on the task and select "run" If it does that then it will run successfully when you are logged off.

Step 1 is probably different for Windows 7.
 
Thanks for the response. I've checked and everything seems to be setup according to that list.

  1. I've got it set to Windows 7/Server 2008 (have also tried the Vista option but no joy either)
  2. I've got the path to the batch file in the Started In box
  3. I'm running it under an admin account that has full access to both the local machine and the server directory
  4. The admin account is a member of the local admin
  5. The task is set to run whether the user is logged in or not
  6. If I right click the batch file and select open it runs just fine, its only with task scheduler it doesn't copy (but it does run as the log.txt file is being updated)

Its bloomin' annoying!!
 
Try sticking the output from the copy command into the log file to.

Is the p:\ a network location by any chance? the batch file will need to be run using a network user if thats the case ;)
 
I assume P is a mapped drive?

Is it mapped in all user accounts?

I would just use

copy /Y "\\servername\share\db\file1.DBF" "c:\db"
 
Try sticking the output from the copy command into the log file to.

Is the p:\ a network location by any chance? the batch file will need to be run using a network user if thats the case ;)

Yes it is!!

I assume P is a mapped drive?

Is it mapped in all user accounts?

I would just use

copy /Y "\\servername\share\db\file1.DBF" "c:\db"

Bingo, works with the hostname!! Cheers everyone.
 
Back
Top Bottom