Run a batch file from Task Scheduler is not workin

2019-02-13 18:03发布

Run a batch file from Task Scheduler is not working with a java command inside the .bat file. If I run the .bat file manually its working good.

Here is the simple .bat file I'm trying to schedule

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24;
set CMD= "%JAVA_HOME%\bin\java" -version

echo %CMD%
%CMD%

7条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-13 18:05

What a coworker discovered on something he had that wasn't working, and I have verified on the system I had that wasn't working is the following:

When the whole task is initially setup, you HAVE TO initially use the radio button "Run only when user is logged on". It will ask for your password for the change.

Now run the task.

Verify that whatever the batch was supposed to do, did happen.

And THEN change to the radio button BACK TO 'Run whether user is logged on or not."

This solved a problem for both of us that we had individually been working on for hours.

Side notes: both issues were also trying to elicit a 3rd party FTP app (WinSCP and WinFTP respectively) in each of our cases. Regular "inhouse" batch/tasks were having no issues.

查看更多
Melony?
3楼-- · 2019-02-13 18:06

What worked for me was running the task as "Users" ( computername\Users ). Once I did that, and "run with highest privileges" checked, it ran without a hitch.

查看更多
The star\"
4楼-- · 2019-02-13 18:14

Giving the full path of java.exe in the batch file fixed it for me. In a notepad, I typed the following line:

"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -jar "C:\Users\usernameXXXX\Documents\NetBeansProjects\JavaApplication5\dist\JavaApplication5.jar"

Save this as a app1.bat file (C:\temp\app1.bat)

In the Actions tab of the task scheduler, give the path to the batch file, i.e, C:\temp\app1.bat Also, be careful in the Conditions tab of task scheduler- make sure you uncheck "Start the task only if the computer is on AC power"

查看更多
何必那么认真
5楼-- · 2019-02-13 18:18

If ixe013's suggestion doesnt work go to

'Actions'
'Edit' the task
'Start in (optional):'  Put the path to the directory  where the script is

So for the last one if you have 'C:\Users\Desktop\script.py' just put in 'C:\Users\Desktop\' in the 'Start in (optional):' field

查看更多
Evening l夕情丶
6楼-- · 2019-02-13 18:20

All other ways did not work for me, I followed this guide: http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/#comment-6873

In order to get the batch file to run, I had to set the "Program\script" box to contain just the name of the script (ie. script.bat) and set the the folder path of the script in the "Start in (optional)" box

查看更多
\"骚年 ilove
7楼-- · 2019-02-13 18:20

I gave full permission to user Everyone from security tab from Properties of the folder in which batch file is. and it started working.

查看更多
登录 后发表回答