1

How can a DOS Batch command file determine if it is being run by Task Scheduler?

David Makogon
  • 2,768
  • 1
  • 20
  • 29
Dan
  • 51
  • 1
  • 5

2 Answers2

1

If you control both the batch and the scheduled task, you could configure it to use a parameter.

Example - in the Scheduled Task, on the Action, you could define a parameter like: /ScheduledTask

In the batch file, you could check for the existence of the command-line parameter:

if /i %1==/ScheduledTask set RUN_BY_TASK_SCHEDULER=1


Related:

0

maybe if the task was scheduled with another account, local or domain.

Inserting an IF based on enviroment variables like %userdomain% or %username%

Regards!