Task Scheduler will not execute a batch file correctly if its emailing something

dalearyous

[H]ard|Gawd
Joined
Jun 21, 2008
Messages
1,922
ok so bare with me for a moment. i am using task scheduler to run a batch file. the ONLY thing the batch file is doing is running a .R file. inside the .R file is some code that depending on the situation fires off some emails. for whatever reason task scheduler will run and supposedly execute the batch file but it will not run correctly. it gets stuck and no emails are sent. if i change the .R code to create a test file it will but it won't send emails.

now here is where its strange. if i don't use task scheduler and simply run the batch file, it runs fine emails get sent etc ...

what am i missing? it seems as if the task scheduler actually cares what code is running. i have tried all sorts of run as administrator stuff or using local administrator or domain administrators. nothing seems to work.
 
ok so bare with me for a moment. i am using task scheduler to run a batch file. the ONLY thing the batch file is doing is running a .R file. inside the .R file is some code that depending on the situation fires off some emails. for whatever reason task scheduler will run and supposedly execute the batch file but it will not run correctly. it gets stuck and no emails are sent. if i change the .R code to create a test file it will but it won't send emails.

now here is where its strange. if i don't use task scheduler and simply run the batch file, it runs fine emails get sent etc ...

what am i missing? it seems as if the task scheduler actually cares what code is running. i have tried all sorts of run as administrator stuff or using local administrator or domain administrators. nothing seems to work.
It's my understanding that since the December update Windows 10 now defaults to PowerShell rather than the classic cmd.exe that *.bat files run in. Got to: Settings/Personalization/Taskbar and click “Replace Command Prompt with Windows PowerShell in the menu when I right-click the Start button or press Windows key+X” slider to OFF. Then do a test run. Hope this helps.
 
i am not sure that is related. like i said, the .bat file runs just fine if you double click on it. using task scheduler to run the .bat file is only when it fails.
 
So the batch file is executing an .r file? How exactly? What program does this? I don't see how the end result of Task Scheduler launching a batch that launches this other file is different from you launching the batch that launches this other file. Unless of course there's more that we don't know. Could be a PATH issue for all we know.

Can you share any of the batch file code?
 
Last edited:
i am not sure that is related. like i said, the .bat file runs just fine if you double click on it. using task scheduler to run the .bat file is only when it fails.
If you're trying to do stuff involving assumed environment variables or other assumed things due to running in the user context, you may need to test if your script is getting those. Is the task running as a user or as a SYSTEM task?
 
There is a task setting to run whether is user is logged in or not, make sure that's checked.

Also there is a local security policy (secpol.msc) to adjust permissions to log on as batch job (add the user the task job is running as).
 
Back
Top