How can a DOS Batch command file determine if it is being run by Task Scheduler?
2 Answers
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:
maybe if the task was scheduled with another account, local or domain.
Inserting an IF based on enviroment variables like %userdomain% or %username%
Regards!