1
1
I have a batch file and a corresponding task entry set up for it- and when I manually run the .bat
file, it runs just fine- but the task scheduler doesn't execute the .bat
file properly.
I believe I set up the task correctly. The "Security options" are properly set up, the trigger is accurate, and the Action has the following parameters:
Action: "Start a program"
Program/script:
"C:\foo\Command Line Utility\TopSecretProject\desiredscript.bat"
Add arguments (optional):
desiredscript.bat
(tried with and without this)Start in (optional):
C:\foo\Command Line Utility\TopSecretProject\
(tried with and without this)
When looking at the history, I see that the task was triggered, the task engine received the message to start the task, the action was started, the task was started, the task process was created, and 36 seconds later, the action and task were completed.
However, the task normally takes about 1-2 minutes to run when the batch file runs normally; incidentally, the expected output of the batch file isn't realized.
My question: how can I troubleshoot this further? Does the very short run time tell us anything beside that something in the Task Scheduler isn't running properly?
Additional details:
Settings:
- "Allow task to be run on demand" is checked;
- "Stop the rask if it runs longer than: " is set to 3 days
- "If the task is already running, then the following rule applies: " is set to "Do not start a new instance"
General:
- "Run whether user is logged on or not" is checked; correct password was entered
- "Run with highest priviledges" (tried with and without this checked)
Look in the event viewer for any errors – DavidPostill – 2017-11-01T17:11:37.553
1Would help to see the actual script or if you get the same problem with a very basic batch file. – Squashman – 2017-11-01T17:16:27.417
You need to be more specific than "The Security Options are properly set up" and "C:\full\path\here" There are several implications around all of this, and you haven't allowed us to see that. Post your exact task scheduler settings and paths. If you want to obscure a username or something like that, fine, but don't strip so much information we can't troubleshoot the problem. Also post the script if you can. – Appleoddity – 2017-11-01T17:17:01.737
@Squashman thanks for the suggestion- I will retry this with using a basic batch file, even though the regular batch file runs fine. – daOnlyBG – 2017-11-01T17:19:03.247
1Thanks for editing, but you're not helping us out here. There are very real implications about WHAT user you are using to run the script, and WHERE the script is located in regards to permissions. If "foo" is any restricted folder like C:\Users or C:\Windows etc. then whatever user you are using to run the script better have full access to that folder. – Appleoddity – 2017-11-01T17:35:56.770
Debug your script - add to each step commands like
echo some text >> /path/log.txt
, until you find the step that is failing. – harrymc – 2017-11-01T17:53:17.9271If your script uses the network, make sure you know theimplications of running it via a scheduled task. – Eugen Rieck – 2017-11-01T17:54:18.543
If you can't provide the code to a batch file, it is going to make it really hard to help you troubleshoot. – Squashman – 2017-11-01T19:04:30.877
1Check Last run result in Task Scheduler. Try Program/script:
C:\Windows\System32\cmd.exe
and Add arguments (optional):/C ">>somefile.txt 2>&1 "C:\foo\Command Line Utility\TopSecretProject\desiredscript.bat""
. Run the task,and then checksomefile.txt
(use fully qualified path with write rights). – JosefZ – 2017-11-01T22:12:31.697