Problems with Windows Task Scheduler

I have a number of tasks that I schedule to run on our server every morning. I had some problems with the batch files executing when it was setup to run whether or not the user was logged in so my scripts are setup to run only when the user is logged in. I run into a problem on Saturdays and workweek holidays when the user is NOT logged in for a variety of reasons.

The user the task is trying to run under is the administrator login and has full permissions.

For the last few months I've had the scripts set to run only when the user is logged in which is fine 90% of the time. I'm getting tired of adjusting my scripts because they did not run the previous day because the user was not logged in. The research I have done so far has indicated that there is a problem with Windows Server R2 SP1 that will not allow the tasks to run using the setting that will log the user in if it does not happen to be logged in.

My research has uncovered a number of "recommended solutions". I've seen information about adjusting permissions on cmd.exe as well as "patches" from Microsoft for a known issue.

The task scheduler does not indicate an error when the script fails to launch when it is set to "run whether users is logged in or not". The task simply says "running" and it appears in the running processes in the task list but never gets to step #1 of the script.

Please current fallback is to develop "Monday scripts" so I can setup scripts to run to pull system statistics for Friday using TODAY-3 for a date instead of my TODAY-1 I use for tasks launched daily.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
I have not had issues running script in the task scheduler when the user is not logged on. There are certain commands that require the user context that shouldn't be used in scheduled tasks if you want them to run when the user isn't logged on. Could you post the script and we might be able to see where it would be hanging up?
First... you probably don't want to run scheduled tasks as your administrator.

My recommendation would be to create another account... a service account used just for tasks. That account may still be a member of the local administrators group, but you should also go into your policy editor and select User Rights Assignments, and allow that account to "Log on as a batch job" and "Log on as a service".
sparker1970Author Commented:
As a follow up to the 2 replies so far...

The script runs perfectly when run manually by double-clicking the bat file. The job also runs when run from within the task scheduler. The commands and coding within the bat file is correct and is not the source of the problem (I have 15 different scripts running a variety of tasks that run into the same issue). The problem is specific to the fact the scheduler will not launch a session when the setting is to run whether or not the user is logged in. Jobs execute fine when the user is logged in.

With regards to using the administrator account for running batch jobs...I understand completely the pros and cons of doing this and I am planning to create a specific user for scheduled tasks once I know the scheduler is working. Right now our servers reboot each night launching the administrator account on reboot and allowing my scripts to run the next morning. It would be an extra manual step to have another account logged in 24/7 to keep these scripts running. If I get the tasks to work and login as a different user when "user is not logged in" I will have many more options as to alternative user accounts to use.

Right now the problem is simple, I cannot get the task scheduler to work when the setting is to "run whether user is logged in or not". This is the solution I am looking for.
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
If the script is "simply running" when it tries to execute when the user is not logged in then the issue is with the script itself. If you would like to post the script or give us an idea of what the script is, then we might be able to help you troubleshoot it.
OK, well if you want to continue running the script with the current account, then go into secpol.msc and go into Security, and then User Rights Assignments, and make sure that account has the right to "Log on as a batch job".
sparker1970Author Commented:
Here is one of the scripts:

1 move "N:\Scheduled Reports\RPC Report\WEBE_DISCV_*.xlsx" "N:\Scheduled Reports\RPC Report\OldReports\"

2 "C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.exe" "N:\Client Reporting\Client Database.accdb" /x ClientRPC_(Daily)

**The line numbers are for reference only and are not in the actual bat file.

There are 2 lines of "code". The first moves files from the top folder in a tree and the second line opens Access and launches a macro.

Like I said. This script executes as expected when the user is logged in, when run manually thru the scheduler, or run manually outside of the scheduler.
Running these while you are logged in uses the security context of the account you are logged in with. Trying to execute these as a scheduled task removes that security context, and some of what you are doing requires it to be there. That's why allowing the account to log on as a batch job should help, because it tells the scheduler to log on to perform the batch job, thereby loading the security context.
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Is N:\ a local or mapped drive? If it's a mapped drive then that is why your script only runs when you're logged on. You'll need to use the UNC path.
sparker1970Author Commented:
I log on to the computer as the administrator when I set up the tasks. I am also logged in as the administrator when I am testing the batch script using the scheduler. It should be the exact same security profile that executes the script. Since everything is working except when the user is not logged on I suspect the problem exists within windows scheduler and it not logging in with the user credentials I provide when setting up the task.

Granted I'm not an expert by any stretch but if I am logged onto the computer as the administrator and the script works, and the script works from the scheduler when the administrator is logged in, and the script works when run manually as the administrator or any other authorized user.

I see the problem as having something to do with the scheduler not properly logging in using the username and password provided since everything else works under the login when done manually or scheduled when user is logged in.
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
When the script executes when the user is not logged on the user's environment is not available. Therefore items specific to the user environment, like mapped drives, are not available.

Is "N:\" a mapped drive?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sparker1970Author Commented:
Thanks Jeremy...I checked with one of my network guys and he confirmed that the normal scripts to map the network drives will not be launched by a user login from the task scheduler. I am working the mapping script into my batch scripts to properly map the drives and verify that works. I appreciate the simple way you explained it as well. The user does have all the correct security permissions to perform the tasks when logged in but those network drives are not mapped and the script does not "find" the database to open to run the macro. I will update this feed once I can test my logon script in conjunction with my current scripts.
sparker1970Author Commented:
Thanks for the simple explanation and not over-complicating your answer. The solution makes perfect sense and is something outside my area of knowledge since I rarely handle user accounts or login scripts.
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Glad to help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.