Solved

Problems with Windows Task Scheduler

Posted on 2014-01-06
15
1,322 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sccm importing drivers 4 64
Deploying packaged application using SCCM steps ? 4 67
Backup application that will backup to google cloud 12 106
Problem to Citrix 2 12
Problem Description: Actually I found the below issue with some customers after migration from SMS 2003 to SCCM 2007 and epically if they change site code, some clients may appear in the console with old site code, plus old sites still appearing …
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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