Windows Scheduled task succeeds but returns result 0x1
Scheduled TasksScheduled Tasks Problem Overview
I have a scheduled task on a Windows 2008 R2 server. The task includes a Start In directory entry. The task runs, and the batch file it runs does what it is supposed to do. When I run the batch file from a command prompt, I see no errors. The problem is that the "Last run result" is 0x1
(incorrect function call).
I did get this at one time with an incorrect DOS statement IF EXISTS file.txt DO (Copy file.txt file1.txt)
that was corrected by dropping the DO
statement. The current batch file does not show me any errors or warnings.
Why am I getting a 0x1
result?
Batch file that is run:
PUSHD \\JUKEBOX4\Archives\CallRecording
REM only move csv and wma together. wma should be created last.
IF NOT EXIST C:\CallRecording (MKDIR C:\CallRecording)
FOR /f %%f IN ('DIR /b *.wma') DO (
IF EXIST %%~nf.csv (MOVE /Y %%~nf.* C:\CallRecording\)
)
POPD
CD /D "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload"
CollybusUpload.exe
POPD
Info on scheduled task setup:
- Program to run:
C:\Program Files (x86)\Olim, LLC\Collybus DR Upload\CallRecordingUploadFromH.cmd
- Start in:
C:\Program Files (x86)\Olim, LLC\Collybus DR Upload
- Run whether user is logged on or not, highest privileges.
History screen, task completed entry >"Task Scheduler successfully completed task "\Call recording upload to portal from NH" , instance "{1449ad42-2210-427a-bd69-2c15e35340e6}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 1."
First screen of Task Scheduler shows "Run Result" of "Success"
Scheduled Tasks Solutions
Solution 1 - Scheduled Tasks
It seems many users are having issues with this. Here are some fixes:
-
Right click on your task > "Properties" > "Actions" > "Edit" | Put ONLY the file name under 'Program/Script', no quotes and ONLY the directory under 'Start in' as described, again no quotes.
-
Right click on your task > "Properties" > "General" | Test with any/all of the following:
- "Run with highest privileges" (test both options)
- "Run wheter user is logged on or not" (test both options)
- Check that "Configure for" is set to your machine's OS version
- Make sure the user account running the program has the right permissions
Solution 2 - Scheduled Tasks
I found that I have ticked "Run whether user is logged on or not" and it returns a silent failure.
When I changed tick "Run only when user is logged on" instead it works for me.
Solution 3 - Scheduled Tasks
I've had the same problem. It is just a batch-file, working when manually started, but not working as a scheduled task.
there were drive-letters in the batch-file like this:
put z:\folder\file.ext
seems like you should not use drive-letters, they are bound to the user, who created them - for me this little change made it work again:
put \\server\folder\file.ext
Solution 4 - Scheduled Tasks
Windows Task scheduler (Windows server 2008r2)
Same error for me (last run result: 0x1)
Tabs
- Action: remove quotes/double-quotes in
> program/script
and
> start in
even if there is spaces in the path name...
- General:
> Run with highest privileges
and
> configure for your OS...
Now it work!
last run result: The operation completed successfully
Solution 5 - Scheduled Tasks
For Powershell scripts
I have seen this problem multiple times while scheduling Powershell scripts with parameters on multiple Windows servers. The solution has always been to use the -File parameter:
- Under "Actions" --> "Program / Script" Type: "Powershell"
- Under "Add arguments", instead of just typeing "C:/script/test.ps1" use -File "C:/script/test.ps1"
Happy scheduling!
Solution 6 - Scheduled Tasks
This answer was originally edited into the question by the asker.
The problem was that the batch file WAS throwing a silent error. The final POPD was doing no work and was incorrectly called with no opening PUSHD.
Broken code:
CD /D "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload" CALL CollybusUpload.exe POPD
Correct code:
PUSHD "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload" CALL CollybusUpload.exe POPD
Solution 7 - Scheduled Tasks
I found that the problem was to do with Powershell not being able to run scripts, if that's the case for you, here is the solution.
Solution 8 - Scheduled Tasks
In my case it was an encoding issue. We wanted to start en existing batch file, and it resulted in "return code 1", and the desired action wasn't performed. I've accidentally found that the batch file was shown in Notepad as one with UTF-8 encoding (actually without any reason, as we have no special characters in the text). I saved it as ANSI, and it solved the problem for us. Might be, that it was a kind of encoding corruption in the file that prohibited Task Scheduler and cmd.exe to open the file, although it was displayed correctly in Notepad.
Solution 9 - Scheduled Tasks
Probably not the cause of the OP's problem; for me the problem was caused by the fact that my program called a SQL function, and the service account the windows task was set up with did not have the required SQL permissions. That also gives a 0x1
Solution 10 - Scheduled Tasks
I was running a PowerShell script into the task scheduller but i forgot to enable the execution-policy to unrestricted, in an elevated PowerShell console:
Set-ExecutionPolicy Unrestricted
After that, the error disappeared (0x1).
Solution 11 - Scheduled Tasks
On our servers it was a problem with the system path. After upgrading PHP runtime (using installation directory whose name includes version number) and updating the path in system variable PATH
we were getting status 0x1
. System restart corrected the issue. Restarting Task Manager
service might have done it, too.
Solution 12 - Scheduled Tasks
Just had the same problem here. In my case, the bat files had space " " After getting rid of spaces from filename and change into underscore, bat file worked
sample before it wont start
> "x:\Update & pull.bat"
after rename
> "x:\Update_and_pull.bat"
Solution 13 - Scheduled Tasks
For me the problem was the PowerShell script being ran had #Requires -RunAsAdministrator
at the top, meaning it needs to run in an elevated command prompt as an Admin, but the user the Scheduled Task was set to run as wasn't an admin on the local computer. So even though Run with highest privileges
was checked in the scheduled task, I still had to make the user an Administrator on the computer. Once I did that, the script ran as expected.
Solution 14 - Scheduled Tasks
It turns out that a FTP download call using winscp as last thing to do in the batch caused the problem. After inserting the echo command it works fine. Guess the problems source could be the winscp.exe which do not correctly report the end of the current task to the OS.
del "C:\_ftpcrawler\Account Export.csv" /S /Q
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script="C:\_isource\scripte\data.txt"
echo Download ausgeführt am %date%%time% >> C:\_isource\scripte\data.log