Dr_Fox
asked on
Server 2008 Task Scheduler not running batch file
This should be really simple, but its not. I've created a test batch file which consists of the following and placed it in my root directory. The result should create a .txt file at the end. I can manually execute it with no problem.
@echo off
echo %date% %time% %UserName% >> c:\test.txt
My problem is, when I try to run this via task scheduler in Server 2008 R2 (My web box) it gives me the OpCode of 2 (File not found). In Task Scheduler, I've told it the start in folder of C:\. In my AD Group Policy, I've given permission to Log on as batch job to my account (Administrator) and did a gpupdate.exe /force, my event viewer for Task scheduler says it finished, however it returns the code of 2.
Any suggestions?
I've tried this test with .vbs, .CMD, and with ps1 examples all to no avail.
@echo off
echo %date% %time% %UserName% >> c:\test.txt
My problem is, when I try to run this via task scheduler in Server 2008 R2 (My web box) it gives me the OpCode of 2 (File not found). In Task Scheduler, I've told it the start in folder of C:\. In my AD Group Policy, I've given permission to Log on as batch job to my account (Administrator) and did a gpupdate.exe /force, my event viewer for Task scheduler says it finished, however it returns the code of 2.
Any suggestions?
I've tried this test with .vbs, .CMD, and with ps1 examples all to no avail.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
1. Make sure you aren't running and storing your script in the root of C.
2. Turn off UAC, UAC prevented me from being able to run my scripts when unattended.
3. If you are running Active Directory, make sure you make your services account has access in the Group Policy Management Editor for Log on as a batch job that can be found under Computer Configuration/Policies/Win
4. When creating your Task, the field for Start In (Optional) is not really optional, put in the path of your script location, otherwise it will give you errors of it can't find the file specified.
5. If your using a batch or CMD file to fire off your script, make sure you put in an error code, otherwise Task Scheduler will not know that the process is done. SET ERRORLEV=0 or EXIT 0. This way Task Scheduler will stop running the script/batch/cmd file after it has been executed.
I believe that was it. Hopefully my post will help others as well.