Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file from scheduled task returns code 2147942401

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. Properties - General Actions - Edit Action

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 correctenter image description here

like image 349
Sbanga Avatar asked Jan 19 '18 15:01

Sbanga


People also ask

How do I run a scheduled task in a batch file?

Run batch file with Task SchedulerOpen Start. Search for Task Scheduler and click the top result to open the app. Right-click the "Task Scheduler Library" branch and select the New Folder option. Confirm a name for the folder — for example, MyScripts.

How do I run a scheduled task from the command line?

View scheduled tasks At the command prompt, type the net start command, and then press ENTER to display a list of currently running services. At the command prompt, do one of the following steps: To view a list of tasks that you scheduled by using the at command, type the at \\computername line, and then press ENTER.

How do I clone a scheduled task?

To move or copy a task between machines, perform the following steps: Open Scheduled Tasks on your local machine (go to Start, Settings, Control Panel, Scheduled Tasks). Right-click the task your want to move or copy. If you want to copy the task, select Copy, and if you want to move the task, select Cut.

What is 0x1 in scheduled task?

Task scheduler last run result 0x1 mostly cause by privilege issue. For example, user do not have sufficient privilege to execute the task at the specified location or the process unable to locate the file for some reason.


1 Answers

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

  • Type in secpol.msc /s
  • Select "Local Policies" in MSC snap in
  • Select "User Rights Assignment"
  • Right click on "Log on as batch job" and select Properties
  • Click "Add User or Group", and include the relevant user.

Local Security Policy Snap-In

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.

like image 174
woodvi Avatar answered Oct 15 '22 10:10

woodvi