Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Schedule a batch file in Win 7

Status
Not open for further replies.

plesbit

IS-IT--Management
Jan 29, 2010
16
GB
I am trying to get a batch file to run according to a schedule in Windows 7. The computer seems to have other ideas and so far it is proving a fairly one sided battle of wills.

The idea - that it will run the batch file at 1910hrs each evening to move a file / group of files from a local folder on that PC to a network drive.

The problem - come the scheduled event nothing happens. If you choose to run the task now nothing happens either. It is almost as if the event is just being ignored. However drilling down into the Task Scheduler logs there are 8 references to it, confirming it was initiated, started and completed successfully. The unmoved files say otherwise. If you run the batch file by double clicking it it runs as designed.

So the file works and does its job when manually run which points the finger at the scheduler. The scheduling system appears to be working in that it calls the file at the scheduled time or when told to run now. But for some reason the file does not actually run when called by the scheduler. What have I done wrong?

The specifics are:

- Trigger at allotted time according to schedule.
- Action: Start a Program: C:\SW-BK\mv-bkp.bat
- Run as: DOMAIN\administrator

I have dumped a sizable chunk of files in that folder for testing purposes and it takes about 30 secs to move them all out again so the DOS window opened by the bat file should sit on the screen for quite some time when running. However it doesn't appear at all when run from the task scheduler which appears to confirm that it never actually starts.
 
Trial and error and we might have got there. It seems to have objected to being set to run whether a user was logged in or not (even though a domain admin account had been specified to run under). Changing it to run only when a user was logged in seems to have fixed the problem - either that or it had finished toying with me and decided to start working!

In either case, that is a solution I can live with - the machine is always logged in but the console is kept locked.
 
Hi there,

Thanks for taking the time to read and offer suggestions.

I have read the thread you linked to and I am not certain that it is the same problem. In that thread the OP states that the scheduler logs show the job as unable to start and state a reason. My scheduler logs showed that the job started, ran and was completed successfully. The scheduler had no knowledge of an error but the reality was that the batch file never actually ran.

Interesting though that one of the followups asks if the job is specified to run whether logged in or not. Ours was specified to run that way and it didn't work but as soon as I changed it to run only if logged in suddenly it started to work so I consider the matter resolved, though I still find it a little odd that it behaves like that.
 
Well, other possibilities might be that the user context the scheduled task runs under does not have network access rights (probably unlikely) or you are trying to use a mapped drive letter that doesn't exist unless the user's profile is loaded (via interactive logon).

If the latter, you might use UNC paths or map a letter within your .BAT/.CMD file via NET USE.

If it is clear the task actually runs, you might try capturing output from the commands to a text file using output redirection. Maybe your "moves" are all failing?

 
Apologies for the delay in replying.

You have answered the question and actually it's obvious. The batch file does copy to a network drive using the drive letter so unless there is an interactive logon / profile loaded the path is not defined.

Iirc when I originally wrote the file I did try to use the unc path but DOS would not accept it. I didn't look further into the issue and, to be honest, we are happy to have the console logged in but locked so this is no longer an issue that requires fixing as the batch file has been running quite happily for a few weeks now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top