Fix Task Scheduler 0x1 Return Error Code – Best Solutions

Task scheduler 0x1 error is a common error appearing when you scheduling mainly batches or scripts. From the error return code, you cannot understand where is the issue. Common the issue is related to the script or batch finish with any error or fails to find something it’s looking for and can’t pass to the task scheduler successfully status. To find the issue you will need to troubleshoot some solutions. We will try to present and explain some of the common solutions about return code 0x1.

Error message and view:

Task Scheduler 0x1

How to Fix Task scheduler 0x1

Fix task scheduler last run result 0x1:

Fix return code 0x1 with long solution

1. Solutions about “Action Tab”

If you are trying to run the script or batch in map drive instead of specifying the latter try to use the full UNC path. For example:

Instead of M:\test\ use \\(IP or servername)\test\

UNC path

Try to configure the path on ‘Start In’ box like below:

Configure path on start in

Configure path on start in

Especially on scripts and batches windows has the problem to understand paths with spaces if they are not quoted. Try to use quotes on paths with spaces on task schedule configuration or on scripts and batches.

Quote the paths

2. State all paths

Try to explicitly state all paths used in the scripts or batches files. Don’t use short path

e. g. the code in Test. bat

call test. bat > test. log

call “D:\Test Path\test. cmd”> “D:\Test Path\test. log”

3. Exit on scripts

Sometimes the scripts stay running and can’t pass the finishing status to the task scheduler. To avoid this try to state exit or close command on the end of the scripts or batches.

4. Check the scripts for error

Even if the script or batch runs correctly sometimes return error code. To troubleshoot this you can run the script or batches manually using a pause statement at the end of it.

To get the error code to add one more line on the end of the script or batch as below:

echo ErrorCode = %ErrorLevel%

To fix this you can add another command in the end in order to return an error status code 0. For example, add one line to write the current time.

5. Specify “stop task”.

In cases where the task stays running, you can configure the Task schedule to stop. To do this:

So the next day the scheduler will be ready to start.

Conclusions error code 0x1:

Above we included almost all solutions and troubleshooting regarding the task scheduler 0x1 error code. Error 0x1 his hard to debug and need to try a couple of solutions in order to find the reason for your environment.

Используем Powershell для работы с планировщиком заданий для создания и изменения задач

В Windows есть механизм под названием ‘Планировщик заданий’ (Task Scheduler). Основная задача планировщика — выполнение задач в определенный момент времени или при определенном действии. В этой статье будет рассмотрены варианты работы с ним через Powershell. На примере мы создадим задание в виде скрипта с Powershell, изменим и удалим его используя только команды.

Работа планировщика в Powershell

Отличительной чертой работы Powershell является то, что мы должны создать каждый из объектов (результат команд) планировщика отдельно, а затем объединить их с помощью 1 команды. Сами объекты делятся на следующие:

3 и 4 пункт не является обязательными при создании задачи т. к. уже имеет настройки по умолчанию.

За создание задач в планировщике отвечает модуль ScheduledTasks, который имеет следующие команды:

Создание скрипта для тестирования

Что бы продемонстрировать работу планировщика я создам скрипт, который будет сохранять логи с журнала Windows в папку ‘logs’. Ниже находится сам скрипт:

Команды выше не должны выдавать каких либо ошибок. Ошибка может быть, например, с несуществующей папкой ‘logs’. Сам скрипт я сохранил по пути ‘C:\scheduler_task. ps1’. Его запуск не выдает каких-то ошибок:

У вас так же будет создан файл в папке ‘logs’.

Создание выполняемого действия для планировщика

Для создания ‘action’ мы должны указать программу и аргументы. В качестве программы будет сам интерпретатор ‘powershell. exe’, а аргументом будет путь до скрипта. Как говорилось раньше у нас будет несколько объектов (результат команд) и все их нужно будет объединить. Что бы это было возможным мы должны поместить результаты работы в переменные:

Мы так же можем указать параметр ‘WorkingDirectory’, который определяет откуда и будет запущена программа. Учитывая, что ‘powershell. exe’ виден через системные переменные использовать параметр ‘WorkingDirectory’ нам не требуется.

Действия выше аналогичны следующим настройкам в интерфейсе (т. е. так мы обычно добавляем скрипт Powershell в планировщик):

Создание временного события — триггера

Следующим мы определим, когда мы будем запускать задачу. Это делается с помощью команды ‘New-ScheduledTaskTrigger’. Эта команда имеет множество параметров, которые делятся на системные события и временные.

Системные события, которые мы можем использовать, следующие:

Аргументы связанные со временем:

Большую часть команд, связанных со временем, мы можем сочетать вместе. Так, например, мы создадим триггер выполнится однажды в 13:00:

Источники:

https://www. get-itsolutions. com/task-scheduler-0x1/

https://darksf. ru/2019/12/24/ispolzuem-powershell-dlya-raboty-s-planirovshhi/

Понравилась статья? Поделиться с друзьями:
Добавить комментарий

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: