Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 567 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run a batch file from Task Scheduler is not working with a java command

#1
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%
Reply

#2
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
Reply

#3
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.
Reply

#4
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"
Reply

#5
All other ways did not work for me, I followed this guide:

[To see links please register here]


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
Reply

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

#7
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.
Reply

#8
When you type `batchfile.bat` on the command line, you are telling `cmd.exe` to read the file and execute each line it finds in it. When you double-click on your batch file in explorer, it calls `cmd.exe` for you, after reading the file associations in the registry.

Task Manager is not so kind.

So for your task to work, schedule it like this (from memory, not on a Windows box right now) :

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

For extra robustness, you could make sure you batch file run from a known directory, like the one that it reside in, by adding this at the top:

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

And finally you could disable CMD autorun entry by adding `/d` right after `cmd` like this:

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

#9
I had the same problem, and to solve it, I put the next command line into the batch file:

`cd "CURRENT_DIRECTORY"`

where `CURRENT_DIRECTORY` is the directory where the batch file is located.

Example:
Suppose i have my batch file named **test.bat** located into **c:\windows\system32\mytest**

in my test.bat file, i introduce the next command line:

`cd c:\windows\system32\mytest`
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through