Server 2008 Task Scheduler not running batch file

Dr_Fox
Dr_Fox used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
can you try store the files in different location other than c: especially the result txt file because c: by default is protected by User Account Control UAC,

Author

Commented:
Waseems, this did the trick for my simple .bat file.  I will mark you as the accepted solution.  For others that are having challenges with this, I have a .vbs that I created that starts and stops my IIS services on my IIS 7.0 web server.  In order to make that work, there were a few more hoops to jump through.

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/Windows Settings/Security Settings/Local Policies/User Rights Assignment.  If you are not using AD, then in gpedit.msc on the local machine, you have to set the service account Log on as a batch job in Local Computer Policy/Computer Configuration/Security Settings/Local Policies/User Rights Assignment.  Don't forget to do a gpupdate /force to foce your group policies to update.
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial