Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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\)
CD /D "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload"
CollybusUpload.exe

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"

    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, 2019 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 4, 2019 at 21:07 Does this answer your question? Why does my Task Scheduler task fail with error 2147942667? – TylerH Jun 8, 2022 at 13:37
  • 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
  • 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, 2016 at 17:01 Your first bullet point about "start in" parameter fixed this issue for me. Thanks a ton. – VHS Aug 27, 2017 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, 2018 at 11:06 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, 2019 at 6:35

    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
                    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 2, 2022 at 20:35
    

    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!

    Under "Actions" --> "Program / Script" i used C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe – 3rdi Nov 21, 2021 at 14:41 Access your SQL server with Management Studio. Right click on security and add new login. Use the domain name too, for the windows account running you scheduled task, like SomeDomain\SomeUser. Before hitton OK to create the login, select "User Mapping" on the left and give this new login the required databases. – opperman.eric May 10 at 3:15

    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
    

    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.

    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.

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

    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"

    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.

    Since there is always more than one reason this could happen I thought I'd share some troubleshooting tips that helped me diagnose my issue.

  • Always adding a "start in" parameter first since thats an easy fix, even just adding the drive letter can help, e.g. C:\
  • If you're running "whether user is logged on or not" and it is failing it might be an issue with your user and/or user environment.
  • Switch the task to run only when user is logged in temporarily for troubleshooting purposes.
  • Make sure you're actually logged in AS the user you're telling the task to run as. (PATH and other environment variables are different by user and if you see the task running on one user successfully that doesn't necessarily mean it will run successfully for another user even if they're in the same security group.)
  • Add pauses or some other type of debugging to your script to give you time to see any errors that may pop up.
  • Perform a manual run from the task scheduler window.
  • Fix any errors you see from your debugging statements. Rinse and repeat.
  • If it runs successfully switch back to run "whether user is logged on or not" and try another manual run. If it works now you're all set.
  • If nothing has helped so far you might need to dig in deeper to your user and file privileges. My troubleshooting tips assume that you have been able to get a past task running using a specific user login already. They don't cover building a scheduled task from a fresh install necessarily. Luckily I haven't had to do that.
  • 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
                    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, 2017 at 6:59