Reputation: 599
I am trying to schedule a job to run a batch file with Windows 10 Task Scheduler, but it results in return code 2147942401.
The batch file is on remote location so I am giving the absolute path
"\\server1\file transfers\data files\inbound\abc\csv\excel-to-csv.bat"
If I run the batch script with command prompt then it work fine.
The batch script is to convert excel to file to csv.
Content of the script is:
FOR /f "delims=" %%i IN ("\\server1\file transfers\Data Files\Inbound\abc\CSV\*.xlsx" ) DO to-csv.vbs "\\server1\file transfers\Data Files\Inbound\abc\*.xlsx" "%%~ni.csv"
Its calling another VB script which is to-cvs.vbs
If i make changes in Action tab as mention by @Steinspecht(Task scheduler- task completed “successfully” with exit code 0x8007001) then also i am getting the code 2147942401
Not sure whether Add a arguments is written correct
Upvotes: 45
Views: 280181
Reputation: 477
I had the same error from Task Scheduler but it happened to me when my ps script had incorrect digital signature. I was using ExecutionPolicy with 'AllSigned' and my ps script was digitally signed but meantime I changed something inside the script and the script has to be signed again after such action.
I found out when I ran the script manually from ps and I got this error: {script.ps1} is not digitally signed. You cannot run this script on the current system.
Upvotes: 0
Reputation: 949
I had the same error code in the task scheduler.
The reason was that the user account was set to my user instead of the SYSTEM user. This was important, because the task should run on system start without any user login.
The user account can be set in the "General" tab under "Security settings".
Upvotes: 0
Reputation: 21
Just make sure for each action (.bat files in my case) that the Start-in (optional) path is set to the same folder as the file and does not end with a backslash.
Peter
Upvotes: 0
Reputation: 65
For me, the issue was file was blocked as it was downloaded from Internet. I was seeing this in task scheduler history
Task Scheduler successfully completed task "task name" ,
instance "{id}" , action "Powershell.exe" with return code 2147942401.
To solve this:
Upvotes: 0
Reputation: 2026
The error codes for Task Scheduler are listed as hexadecimal at msdn, and your code 2147942401 converts to hex as 0x80070001 (which is not listed there), but this superuser describes it as an "Illegal Function". He fixed his problem by using "the simplest task scheduler settings and now it works". I note that he only runs his task when the user is logged in, so he doesn't need "Log on as a batch job".
If you want to run the batch job when you're not logged in, you need a special privilege called "Log on as a batch job". Note that there is also a "DENY log on as a batch job" privilege, which you wouldn't want.
From Social Technet, you can assign that privilege with
Your task calls a network resource. These powershell scripters recommend bringing those resources to your local machine to eliminate any chance of network/connectivity/permissions issues ... but that may not always be appropriate or practical.
Upvotes: 37
Reputation: 121
For me, the task would sometimes work and sometimes wouldn't. According to the Scheduled Task History, when failing, it would appear as if it's been running for about 40 seconds, doing nothing, and completing action "C:\windows\SYSTEM32\cmd.exe" with return code 2147942401
.
In this case, there was no point messing with the Group Policy settings because sometimes it would work. But not everytime. Which means it's a timing problem, not a Policy problem.
Recreating, reconfiguring my task (as suggested in this SuperUser Q&A) did not fix the problem.
I did also consider butchering my batch file and getting rid of the standard output redirection, thus abandonning the logging capability (and becoming blind). Or simply running an actual "*.exe" process, instead of using a batch file at all. This could potentially have been a solution.
I also considered replacing the "At startup" scheduled task by a full-blown Service, but this would have been an expensive experiment for such a trivial problem.
Ultimately, I remembered that services can be delayed: "Automatic" vs. "Automatic (Delayed Start)". So I imitated this by added a delay on the scheduled task, in the Tasks Scheduler. For "At startup" scheduled tasks, it's the trigger that have individual properties of its own, and that's where the delay can be configured:
I believe my scheduled task was sometimes being started a few milliseconds too early and some OS service or functionality was not yet available or allowed. Simply adding a small delay on the trigger fixed the problem.
Upvotes: 5
Reputation: 634
This error code can also result from a bug/mistake in the actual Powershell script or Batch (.bat) file, even if all task scheduler settings, permissions, etc. are correct; in my case I was referencing a directory that doesn't exist.
Upvotes: 22
Reputation: 61
Throwing another common cause of the error action "powershell.exe" with return code 2147942401
here. If your action arguments are not correct you will also get this error message.
Check that the action argument parameters and parameter values are spaced correctly.
Good example:
-executionpolicy bypass -file "C:\Scripts\ImportFiles.ps1"
Broken Example (no space between the 'file' parameter and it's value):
-executionpolicy bypass -file"C:\Scripts\ImportFiles.ps1"
Upvotes: 5
Reputation: 111
An old question I know, but I was getting 2147942401 error on windows 2016 server.
If you look at the scheduled task properties, on the bottom of the General Tab, it was defaulted to Configure for: Windows Vista, Windows Server 2008.
Changed to Windows Server 2016 and the problem was solved.
Upvotes: 11
Reputation: 1132
M Herbener's answer led to me attempting to run the script manually, to see if the script had an error. It did not, but it did highlight what the problem was as I received the error message:
[my script] cannot be loaded because running scripts is disabled on this system.
The solution, of course, was to run Set-ExecutionPolicy to allow Powershell scripts to run.
Upvotes: 2