How to execute cscript using windows task scheduler?

独自空忆成欢 提交于 2019-12-10 19:56:58

问题


The problem: When I double click the .bat file it executes as expected. When I schedule it in Windows Task Scheduler it executes except the line that has cscript.

Content of .bat file:

@echo off
cls

cscript CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >>log.txt

What is throwing me off is the fact that log.txt gets created indicating that the .bat file is being executed. But .xlsx is not created. However, on manually double clicking .bat both log.txt and test.xlsx is created.

What could be the problem?


回答1:


Resolved!! In the windows task scheduler I had to click "change user or group" button and add "Administrators" group.




回答2:


To help debug the situation, add the following to the end of your cscript command line:

>>c:\MyCScriptOutput.txt 2>&1

Then, check to see if the c:\MyCScriptOutput.txt file has any error message(s) in it. If it does, please add this information (both the command line and the output) to your question.

I'm speculating, but the problem might be that cscript is trying and failing to run interactively, so you could try replacing "cscript" in your command line with "cscript //Nologo //B", to see if that fixes it.




回答3:


The main problem is you don't specify full path to your CSV_To_Excel.vbs Scheduler execute script from c:\windows\system32 (where schtasks.exe located) So, your batch call to cscript should be

cscript %~dp0\CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >> %~dp0\log.txt



来源:https://stackoverflow.com/questions/12628278/how-to-execute-cscript-using-windows-task-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!