.bat Script not running via Task Scheduler

xhope 221 Reputation points
2023-10-15T08:50:31.57+00:00

I have a .bat script that works perfectly when running normally, but when I run it through Task Scheduler, it doesn't work at all.

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2023-10-15T09:21:54.4666667+00:00

    One post is quite enough.

    https://learn.microsoft.com/en-us/answers/questions/1392070/bat-script-not-running-via-task-scheduler

    https://learn.microsoft.com/en-us/answers/questions/1392069/bat-script-not-running-via-task-scheduler

    it doesn't work at all.

    We don't know your script and without an error message we can't guess.

    You have to provide more details (instead posting several time without usefull informations).


  2. MotoX80 36,291 Reputation points
    2023-10-15T14:41:29+00:00

    The script was used to copy a file from a network driver to my local server.

    The task scheduler performs a user impersonation, not a full desktop logon. If your script references a drive letter, it is probably not getting mapped. Use a UNC path instead (\\servername\sharename).

    Capture stdout and stderr to see what the bat file does. Set the scheduled task to execute program "cmd.exe". In the arguments field set it like this example. Be sure to put quotes around the log file name.

    /c C:\Scripts\MyScript.bat  1>>"C:\Scripts\Logs\MyScript-%date:~10,4%-%date:~4,2%%date:~7,2%.log" 2>&1
    

    That will create a daily log file of all executions of the task. Review the log to see what the program did. You might want to also add ECHO statements to the bat file to output the date+time and any other diagnostic information.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.