Question about scheduled tasks and batch files

  • Thread starter Thread starter ajf
  • Start date Start date

ajf

ajf

Soldato
Joined
30 Oct 2006
Posts
3,067
Location
Worcestershire, UK
Scenario.
Server 2003. I want to run a scheduled task that runs when not logged in that copies a directory from the server to a share on a NAS box.
Is this possible?

I have used basic xcopy batch file to run it whilst logged in as I can just map a drive to the NAS box share first.
How do I set the batch file to point to a network drive when not logged in though - is it possible?
Currently the batch files just fails.
 
I imagine you can use the UNC path to the server in the batch file.

ie. \\server1\files\something\text.txt
 
Paste your current batch file.

Also who is it run as? There's also an option to "run only if logged on" when setting up the scheduled task (although I'm sure you've seen that).
 
Use the UNC path in the batch file. When you create the scheduled job and set to run while not logged in, it will ask you to enter credentials of a user to run the job as. As long a the user has permissions the job will run if no-one is logged on.
 
Thank you
I will give this a try.
Thought it should be an easy one but scripts I have never go the hang of. lol

Andrew
 
If you have problems getting your batch file to work, the following simple vbs will work:

Code:
On Error Resume Next
Set objFso = CreateObject("Scripting.FileSystemObject")
objFso.CopyFolder "\\server\share\folder1", "\\nas\share\folder1", True
objFso.CopyFolder "\\server\share\folder2", "\\nas\share\folder2", True
objFso.CopyFolder "\\server\share\folder3", "\\nas\share\folder3", True

Copy it into notepad, change the UNC paths to reflect your environment and save it as CopyFolder.vbs. You can copy as many folders/directories as you require, just add in more objFso.CopyFolder lines or delete some as needed.

When you create your scheduled task, set it to run this vbs, specify an account that has access to both locations to run it, and finally, ensure that "Run only if logged on" is NOT ticked.
 
Last edited:
I thought I had this cracked. Using the UNC worked but...

I have seem to have a strange (?) problem.
If the server is logged off the task runs fine and continues to run when I then log in.
However is SEEMS as if when I log off the task is stopped.
It certainly stops at some point after I have been on the server as the copying halts half way through and it only seems to happen in the above scenario.

If I run the task logged in or never log in whilst it runs it seems to complete without issue.

Is this possible - or just coincidence?
I log in using the same credentials as those given to run the scheduled task - could this be the issue?

I can try the vbs but just want to know why this doesn't work!

Andrew
 
Back
Top Bottom