55

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"

Michael
  • 7,248
  • 5
  • 56
  • 81
user241099
  • 669
  • 2
  • 6
  • 6
  • did you resolve your problem? I set up to run a python 3 task in with everything you said but only when user is logged in. The task is successful and I see it execute. I just get a (0x1) error for some reason too. – user3553260 May 21 '19 at 22:23
  • Yes, I resolved it. The issue was the use of commands in the batch file. I had a final command of POPD that had no work to do as there was no preceding PUSHD. – user241099 Jul 04 '19 at 21:07

14 Answers14

60

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:

    1. "Run with highest privileges" (test both options)
    2. "Run wheter user is logged on or not" (test both options)
    3. Check that "Configure for" is set to your machine's OS version
    4. Make sure the user account running the program has the right permissions
full_prog_full
  • 999
  • 9
  • 16
  • This answer definitely saved the day for me - for others, my instance of Windows 2008 server had both options for Windows 2008 and Windows 2008 R2. I think this makes a difference. – Darth Jon May 16 '16 at 17:01
  • 6
    Your first bullet point about "start in" parameter fixed this issue for me. Thanks a ton. – VHS Aug 27 '17 at 17:09
  • thanks, it works. btw: windows is totally sick platform, it's forcing the user to work against the built in tools (brows script to run and then manually remove quotes and split full path to filename and directory). – andrej Mar 23 '18 at 11:06
  • First bullet fixed it for me, after I added `.\ ` in front of the filename. – Jacktose Jul 06 '18 at 22:04
  • I think the executable goes in the program/script area. – user3553260 May 21 '19 at 22:21
  • Nice! for Windows 2016 the bullet is the key. Just the name with the extension in `Program/Script` and the location path in `Start in`. Zenkiú! – Chuck Aguilar Mar 06 '20 at 10:11
  • Using `Browse` button, it takes full path with the file name for `Program/script:` column, which may cause issue for many. Putting only file name there, and path in `Start in (optional)` works. Thanks for pointing it out. – viking Mar 19 '21 at 13:56
  • To whom it may concern: in my case, there was a typo in the ps1 file. `-` was encrypted when copying the script from another server. Check your script for errors as well. The Task scheduler will not point you there – Moslem Ben Dhaou Mar 02 '22 at 23:48
6

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.

lsheng
  • 3,079
  • 8
  • 31
  • 42
  • This proved of use as when set this way the pop up will show, I played a game of trying to hit print screen when the error was occuring before the screen disappeared again. I was able to see that my filepath was wrong. – user3520245 Jun 21 '19 at 06:35
5

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
roeb
  • 425
  • 8
  • 19
  • This is not an issue if you are careful to run the batch file under a user that also has the same drive letters, but it is good practice regardless to use UNC shares instead of mapped drive letters. Just also make sure that the user you are running the process under has permissions to access UNC paths as well. – TylerH Jun 02 '22 at 20:35
3

Windows Task scheduler (Windows server 2008r2)

Same error for me (last run result: 0x1)

Tabs

  1. Action: remove quotes/double-quotes in

program/script

and

start in

even if there is spaces in the path name...

  1. General:

Run with highest privileges

and

configure for your OS...

Now it work!

last run result: The operation completed successfully

navya
  • 45
  • 5
3

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:

  1. Under "Actions" --> "Program / Script" Type: "Powershell"
  2. Under "Add arguments", instead of just typeing "C:/script/test.ps1" use -File "C:/script/test.ps1"

Happy scheduling!

enter image description here

Andreas
  • 657
  • 2
  • 9
  • 19
1

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
HPierce
  • 6,801
  • 7
  • 35
  • 47
1

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.

Stewert
  • 111
  • 1
  • 3
1

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.

pholpar
  • 1,611
  • 2
  • 13
  • 22
1

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

opperman.eric
  • 140
  • 12
0

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

Willi Mentzel
  • 24,988
  • 16
  • 102
  • 110
Jose Ortega
  • 934
  • 12
  • 22
0

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.

Franc Drobnič
  • 885
  • 10
  • 13
0

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"

tryingToLearn
  • 9,007
  • 10
  • 70
  • 99
Ardi
  • 65
  • 7
0

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.

deadlydog
  • 20,951
  • 14
  • 101
  • 112
-1

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
Willi Mentzel
  • 24,988
  • 16
  • 102
  • 110
SimonR
  • 1
  • 1
    If WinSCP reported error (non zero exit code), it did that for a reason. You are just hiding the problem away by adding a dummy command. – Martin Prikryl Sep 19 '17 at 06:59