Search code examples
batch-filejarscheduled-tasksjavaw

Why running .bat file thru Task Scheduler is not starting the .Jar file fully?


Here is what is going on. I have created a .Bat file containing start javaw -jar BTG_Producer.jar When I start this manually by double clicking it will show my java program in my system tray and shows the process "javaw.exe *32" in Windows Task Manager. When I run this thru Task Scheduler it starts the process "javaw.exe" with out the *32 and does not show the program in the system tray. Do you guys know what I am doing wrong?


Solution

  • When you launch a process via Task Scheduler, it may have a different environment than when you launch the process from your desktop. To test this, you can create a task that runs cmd with the /k parameter from the Task Scheduler. When you run it, cmd will open, then you can run set >%userprofile%\Desktop\environment1.txt. Then, open a cmd as you normally do, and run set >%userprofile%\Desktop\environment2.txt. Open the two files side by side, and compare.

    In this case, I suspect your PATH variables are different, which is why 32-bit java is run in one case, and 64-bit in another.

    To fix this, you could explicitly specify the 64-bit javaw.exe in your batch file.

    C:\path\to\javaw.exe instead of just javaw.