Running a batch file from Task Scheduler does not work with java command

Running a batch file from the Task Scheduler does not work with the java command inside the .bat file. If I run the .bat file manually, then it will work well.

Here is a simple .bat file that I plan to schedule

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24; set CMD= "%JAVA_HOME%\bin\java" -version echo %CMD% %CMD% 
+6
source share
7 answers

When you enter batchfile.bat at the command line, you tell cmd.exe to read the file and execute each batchfile.bat line in it. When you double-click on a batch file in Explorer, it calls cmd.exe after reading the file associations in the registry.

Task Manager is not so kind.

So, for your task to work, schedule it as follows (from memory, not from the Windows box):

 cmd /c "c:\full\path\to\your\batchfile.bat" 

For added reliability, you can make sure that the batch file is launched from a known directory, for example, in the one in which it is located by adding it at the top:

 pushd %~dp0 REM .... The original batch file goes here .... popd 

And finally, you can disable CMD autorun recording by adding /d immediately after cmd as follows:

 cmd /d /c "c:\full\path\to\your\batchfile.bat" 
+11
source

If ixe013's suggestion does not work, go to

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

So, for the latter, if you have C: \ Users \ Desktop \ script.py ', simply enter "C: \ Users \ Desktop \" in the "Start (optional):" field

+8
source

For me, it worked as "Users" (computer_name \ Users). As soon as I did this and checked "running with the highest privileges," he ran without difficulty.

+2
source

Providing the full java.exe path in the batch file fixed it for me. In 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 app1.bat file (C: \ temp \ app1.bat)

On the "Actions" tab of the task scheduler, specify the path to the batch file, that is, C: \ temp \ app1.bat. Also, be careful on the "Conditions" tab of the task scheduler - make sure that you uncheck the "Run the task only if if the computer is turned on "

+1
source

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

To run the batch file, I had to set only the script name (ie script.bat) in the "Program \ script" field and set the script path folder in the "Start (optional)" field

0
source

I gave full permission to the "Everyone" user from the "Security" tab from the "Folder Options" in which the batch file is located. and he began to work.

0
source

Which employee discovered something that he had that didn't work, and I checked the system that I didn't work, this is the following:

When the entire task is initially configured, you first use the "Run only at user login" radio button. He will ask for a password to change.

Now run the task.

Make sure everything that the package was supposed to do happened.

And then change to the BACK TO radio button "Run whether the user has been turned on or not."

This solved the problem for both of us, on which we worked for several hours.

Side notes: both problems also tried to be detected by a third-party FTP application (WinSCP and WinFTP, respectively) in each of our cases. Regular "internal" parties / tasks had no problems.

0
source

Source: https://habr.com/ru/post/955709/


All Articles