Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 task scheduler keeps returning operational code 2

I set up a scheduled task to run under my account. Everything it runs, even if it is successful, returns an operational code of (2). I looked this up this error code at the below link, and it claims it cannot find the specific file.

http://www.hiteksoftware.com/knowledge/articles/049.htm

Even if I do something very simple, I get back operational code of (2). For example:

run program: cmd.exe

start in path: c:\windows\system32

I start the task and I see the process running in my task manager, so I kill the task. I then check in the history of scheduled task and it shows up as (2).

Something more realistic of what I am doing:

<?
/* file in c:\php\test.php */
echo "hello";
?>

run program: php.exe

start in path: c:\php

arguments: -f test.php

Everything works in the command line, but Windows schedule task keeps returning operational code (2). I should be seeing an operational code of (0), which means successful, correct?

like image 776
user785179 Avatar asked Oct 18 '12 22:10

user785179


People also ask

What does Operational Code 2 mean in Task Scheduler?

The common codes for scheduled tasks are: 0 or 0x0: The operation completed successfully. 1 or 0x1: Incorrect function called or unknown function called. 2 or 0x2: File not found. 10 or 0xa: The environment is incorrect.

What does 0x1 mean in Task Scheduler?

What does 0x1 mean in Task Scheduler? The error 0x1 will appear in the last run result in a task scheduler if it had an issue running the task. It will have an issue where is can not find a required file, This is usually resolved by setting the start in path within the scheduled task.

Where is Microsoft Windows TaskScheduler operational?

1 Answer. open Event Viewer and navigate to Applications and Services Logs / Microsoft / Windows / TaskScheduler / Optional, you will see all the Task Histories. The . evt files are under C:\Windows\System32\Winevt\Logs directory.


2 Answers

You may not have put a path in the "Start In (Optional) box of the Edit Action dialog box.

Even though you had a path on the program that was being executed, Windows 7 still wants you to tell it where to run the program.

like image 139
tlhumphrey2 Avatar answered Oct 19 '22 07:10

tlhumphrey2


TL/DR: Don't worry about it. This just means the task finished, but tells you nothing about whether it was successful or how it failed. Look at the "Last Run Result" for that information.


The question and the top answer are confusing the notion of a "return code", which shows up in Task Scheduler as the "Last Run Result" with the "OpCode"/"Operational Code" that shows up in the history of a task.

If I create a simple Python program that does nothing more than sys.exit(7), and run it via task scheduler, I get a Last Run Result of 0x7, and an opcode of 2. If I have it do nothing, or sys.exit(0), I get a Last Run Result of "The operation completed successfully (0x0)" and still an opcode of 2. In other words, the return code from the executed program determines the Last Run Result. The OpCode appears to be a constant 2. This also establishes that the opcode 2 is not related to the return code 2 that likely means the file's not found. We know the file was found as it executed, and returned different Last Run Results depending on the code contained.

Further, a Windows forum post points out that this history view is really coming out of the event log. Sure enough, I can find the same events in the event log (always with a value of 2). This means the definition of the OpCode is going to be the same as the definition used for events, and is less of a task scheduler concept than a Windows event concept.

What is an opcode for an event? I've struggled to get a clear answer, but as best I can tell, it appears it's ultimately controlled by the program writing to the event log. There's documentation around for defining opcodes in your program. In this case, the thing writing to the event log would be Task Scheduler itself or something else in Windows.

A final observation: If I go to the event viewer and look for Log: Microsoft-Windows-TaskScheduler/Operational, Source: Microsoft-Windows-TaskScheduler and Event ID: 102,201, add the column for Operational Code, and sort, I see it is always a 2. And events 100 and 200 are always a 1. This applies not just to my manual experiments, but also includes every other random program that's using scheduled tasks, e.g. Dropbox and Google updaters that are working as far as I know.

Put all this together and I would strongly bet that the events generated while starting up a scheduled task are hardcoded by Windows to use an opcode of 1 when writing to the event log, and the events generated while finishing a task (successful or not - which goes in the Last Run Result) are hardcoded by Windows to use an opcode of 2 when writing to the event log. This opcode appears to be a red herring that doesn't affect anything we need to worry about beyond curiosity.

like image 6
ojchase Avatar answered Oct 19 '22 06:10

ojchase