Windows Task Scheduler doesn't start batch fil

2019-03-12 10:12发布

I have a batch file with the code below to stop and start the SQL Report service:

net stop "SQL Server Reporting Services (MSSQLSERVER)" 

timeout /t 10

net start "SQL Server Reporting Services (MSSQLSERVER)"

I have set up the scheduled task to run daily, it currently runs as SYSTEM with the highest privileges set. I have set up the start in folder option on the action, and everything generally seems to be set up correctly. But when I run the task nothing seems to happen, it says the task has run but I cant see that the service has been restarted as it is meant to.

Can someone direct me to what I am missing? Thanks

15条回答
SAY GOODBYE
2楼-- · 2019-03-12 10:15

On a Windows system which supports runas. First, independently run your program by launching it from a command line which was run as that user, like following

runas /user:<domain\username> cmd

Then, in that new command line, cd to the path from where you expect the task launcher to launch your program and type the full arguments, for example.

cd D:\Scripts\, then execute

C:\python27\pthon.exe script.py

Any errors that are being suppressed by task scheduler should come out to command line output and will make things easier to debug.

查看更多
乱世女痞
3楼-- · 2019-03-12 10:16

Wasted a lot of time on this silly issue!

add a cd command to where your batch file resides at the first line of your batch file and see if it resolves the issue.

cd D:\wherever\yourBatch\fileIs

TIP: please use absolute paths, relative paths ideally should not be an issue, but scheduler has an difficult time understanding them.

查看更多
smile是对你的礼貌
4楼-- · 2019-03-12 10:22

Had the same issue, make sure you check "Run only when user is logged on" at least that is what made my bat file alive again.

查看更多
萌系小妹纸
5楼-- · 2019-03-12 10:23

One solution is you can run your '.bat' file with '.vbs' file and you can run this vbs file in windows scheduler.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("cron_jobs.bat"), 0, True

You can do like this and i hope it will fix your issue.

查看更多
Animai°情兽
6楼-- · 2019-03-12 10:23

For me, the problem was caused by the .bat included a cd to a network drive. This failed, and then the later call to the program in that network drive did nothing.

I figured this out by adding > log.txt in the Add arguments field of the Edit action window for the task.

查看更多
Viruses.
7楼-- · 2019-03-12 10:23

I had the same problem and none of the solutions worked. When I checked the history I figured out the issue. I had this warning

Task Scheduler did not launch task "\TASK_NAME"  because instance "{34a206d4-7fce-3895-bfcd-2456f6ed6533}"  of the same task is already running.

In the settings tab there is a drop down option for "If the task is already running, then the following rule applies:" and the default is "Do not start a new instance". Change that to "Run a new instance in parallel" or "Stop the existing instance" based on what you actually need to be done.

I know it's an old thread and multiple solutions are good here, this is just what worked for me. Hope it helps.

查看更多
登录 后发表回答