Summary: My .bat file runs when I manually double-click the file in File Explorer, but it does not run when I try to schedule it in Windows Task Scheduler.
Details:
I have a .bat file that I have stored in a folder. When I open File Explorer and double-click that .bat file, it successfully runs. The .bat file runs a Python script. I am also able to successfully run the Python script manually from Visual Studio Code.
However, when I schedule that same file in Windows Task Scheduler, WTS tells me that it completed the task successfully but when I check my logs I find that the task did not actually run.
When I last triggered the bat file to run in Windows Task Scheduler at 1:11:41 PM, it started the task (100), started the action (200), completed the action (201) and completed the task (102) at 1:11:42 PM.
This is the XML view for the task completed (102) event:
<Provider Name="Microsoft-Windows-TaskScheduler" Guid="{de7b24ea-73c8-4a09-985d-5bdadcfa9017}" />
<EventID>102</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>102</Task>
<Opcode>2</Opcode>
<Keywords>0x8000000000000001</Keywords>
<TimeCreated SystemTime="2024-12-02T19:11:42.2075975Z" />
<EventRecordID>525946</EventRecordID>
<Correlation ActivityID="{4613b91d-77ba-455d-aa2d-fc89b76b6cc0}" />
<Execution ProcessID="2800" ThreadID="42828" />
<Channel>Microsoft-Windows-TaskScheduler/Operational</Channel>
<Computer>(removed by OP)</Computer>
<Security UserID="(removed by OP)" />
</System>
- <EventData Name="TaskSuccessEvent">
<Data Name="TaskName">\pathfolder\file_name_without_file_extension</Data>
<Data Name="UserContext">org_name\user_name</Data>
<Data Name="InstanceId">{4613b91d-77ba-455d-aa2d-fc89b76b6cc0}</Data>
</EventData>
</Event>
I'm seeing in other Microsoft answers that if it can be problematic to supply a path to the Program/Script bank that begins with a letter for a drive. However, I'm not seeing specific information on what I should use instead of this letter drive name. During my googling, I saw another Microsoft Answers where someone linked to two previous Microsoft Answers, but the links were broken:
![editaction](https://learn-attachment.microsoft.com/api/attachments/136ab30d-aa43-4196-9ec6-4de67cd084d0?platform=QnA)
Here are screenshots of my Windows Task Scheduler with sensitive information removed:
General tab:
![bat general](https://learn-attachment.microsoft.com/api/attachments/cc56bac0-e612-45c0-9a12-ae7846c29421?platform=QnA)
Triggers:
![bat trigger](https://learn-attachment.microsoft.com/api/attachments/ecede87b-d523-4c1e-be48-f908f6df4e7f?platform=QnA)
Actions:
![bat actions](https://learn-attachment.microsoft.com/api/attachments/7396a04f-6a7f-4536-84f8-17e9199abd41?platform=QnA)
Edit Action--please note I have tried placing this path within quotation marks and without quotation marks (in screenshot below):
![editaction](https://learn-attachment.microsoft.com/api/attachments/941b6e59-374f-4b55-b9aa-39db66c31de0?platform=QnA)
Conditions:
Settings:
![bat settings](https://learn-attachment.microsoft.com/api/attachments/554a4de4-7c76-42f2-8287-8fe51ab2d8e2?platform=QnA)
This is information on my computer:
Processor 13th Gen Intel(R) Core(TM) i9-13900H 2.60 GHz
Installed RAM 64.0 GB (63.7 GB usable)
System type 64-bit operating system, x64-based processor
Edition Windows 11 Enterprise
Version 22H2