Solved

Problems with Windows Task Scheduler

Posted on 2014-01-06
15
1,276 Views
Last Modified: 2014-01-06
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 help...my 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.
0
Comment
Question by:sparker1970
  • 5
  • 5
  • 5
15 Comments
 
LVL 18

Expert Comment

by:Jeremy Weisinger
ID: 39759681
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?
0
 
LVL 13

Expert Comment

by:dhoffman_98
ID: 39759692
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".
0
 

Author Comment

by:sparker1970
ID: 39759909
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.
0
 
LVL 18

Expert Comment

by:Jeremy Weisinger
ID: 39759929
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.
0
 
LVL 13

Expert Comment

by:dhoffman_98
ID: 39759936
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".
0
 

Author Comment

by:sparker1970
ID: 39759948
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.
0
 
LVL 13

Expert Comment

by:dhoffman_98
ID: 39759967
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.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 18

Expert Comment

by:Jeremy Weisinger
ID: 39759989
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.
0
 

Author Comment

by:sparker1970
ID: 39760011
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.
0
 
LVL 13

Expert Comment

by:dhoffman_98
ID: 39760033
0
 
LVL 13

Expert Comment

by:dhoffman_98
ID: 39760034
(twice)
0
 
LVL 18

Accepted Solution

by:
Jeremy Weisinger earned 500 total points
ID: 39760050
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?
0
 

Author Comment

by:sparker1970
ID: 39760181
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.
0
 

Author Closing Comment

by:sparker1970
ID: 39760186
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.
0
 
LVL 18

Expert Comment

by:Jeremy Weisinger
ID: 39760206
Glad to help
0

Featured Post

Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

Join & Write a Comment

Every system administrator encounters once in while in a problem where the solution seems to be a needle in haystack.  My needle was an anti-virus version causing problems with my Exchange server. I have an HP DL350 with Windows Server 2008 Stand…
Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now