1

I have a batch file that creates a copy of an Access database as a backup and stores it on the network with a date stamp suffixed to the file name. This batch file runs fine on its own and also as a scheduled task while I am logged into the server (Windows server 2008 R2). But despite trying many things I cannot get the scheduled task to run when I am not logged into the server. I have tried configuring the scheduled task properties to run with the highest privileges, tried switching the settings of "run whether user is logged in or not" - and sore password options, tried amending the "Actions" tab by putting the path in the "Start In" parameter and only the batch file name in the "Program" parameter but still nothing works. What am I doing wrong here?

6
  • The first thing I'd do is find out whether the script isn't running at all, or just not being able to copy the file to the network location (I suspect the latter, as that usually needs network credentials). If you haven't already got them, add echo Script run on %DATE% at %TIME% > c:\users\USERNAME\Script.log to the top of the script. If the script is running, it's to do with network credentials. Assuming the script is running as a real user, I've sometimes found an explicit net use x: \\server\sharename helps (re)establish a connection.
    – TripeHound
    Commented Aug 27, 2015 at 10:19
  • @TripeHound Thanks. I placed the echo line at the start of the batch file and then ran it first with me logged into the server and it created and updated the log - the first time. I tried it again with me logged in and it did nothing. I tried a third time with me logged out of the server and again it did nothing
    – mjhenry
    Commented Aug 27, 2015 at 13:10
  • First, I probably should have suggested >> instead of > in the above, so that it appends to the log each time instead of overwriting. Second, if it really did nothing (i.e. the time in the log file didn't change from the first attempt) then it probably is to do with how scheduled tasks run [of which I've little experience]. If the time did change, then it's to do with network permissions.
    – TripeHound
    Commented Aug 27, 2015 at 13:39
  • @TripeHound Thanks again. I now have an entry in the log even if I am not logged into the server. So must be a network permissions problem. I will speak to the company infrastructure team and ask them to assist
    – mjhenry
    Commented Aug 27, 2015 at 14:46
  • @TripeHound Thanks so much. I have it resolved. If you create an answer I will mark it as accepted and score it
    – mjhenry
    Commented Aug 27, 2015 at 16:17

2 Answers 2

1

I have this resolved - you live and learn as they say - and I learned something about batch scripting that I wasn't aware of. Thank you TripeHound for assisting me in pinpointing that it was a network issue.

My batch file was copying the Access database to my company's "I:\" drive, but I learned that while the user is NOT logged into the server the "I:\" drive is NOT recognized and so I changed the I:\ part to the actual server name path, i.e "\the_server\the_drive$" and then it all worked

0

Check with following script replace the the folder name with your network folder name. Disable the "Run only if logged on option" and store the password using "Set password" option.

@echo off set folderName=D:\omal\BackupProjectDaily\%date:~7,2%%date:~4,2%%date:~10,4% echo %folderName% if not exist %folderName% md %folderName% copy 1.txt %folderName%\1-%date:~7,2%%date:~4,2%%date:~-4%.txt pause

exit

Not the answer you're looking for? Browse other questions tagged or ask your own question.