Pregunta

First, just wanted to thank everyone in advance for helping with this, let me take you on my journey...

Task: Run a Java application that is located in a folder on a file server using Windows Task Scheduler, simple enough.

The caveat, is that I would like to utilize the task scheduler option of "Run whether user is logged on or not." and this seems to be a tricky function...

I have set my account as the account that the task is to run under.

What have I tried?

Creating a task based on these actions:

Java.exe -jar "path to share jar"

Java.exe -jar "path to local jar"

Javaw.exe -jar "path to share jar"

Javaw.exe -jar "path to local jar"

All have had the same result with the "Run whether use is logged on or not." option : 0x1

Next, I tried creating a batch file to run this on my behalf and changed the task to run that batch file and I got all the same results. I have read that utilizing the "Start in (optional)" field of an action may solve the problem, but it did not.

After that, I created a .vbs file with code similar to the following:

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0

Set WshShell = Nothing

This achieved a 'silent run', but task scheduler still did not run with the "Run whether use is logged on or not.", and ended in 0x1.

All of these work fine with the "Run only when user is logged on." option.

The reason I want to do it whether I am logged on or not, is because I want to run my application before I come in to work.

Update: I've disocvered a few things. In power options for Windows, I had to enable the ability for scheduled tasks to wake the computer, felt kind of dumb about that one.

Using a simpler task - one that just creates a blank text file - this option works fine. I belive the problem lies with executing Java.

¿Fue útil?

Solución

The task needs a user to run. It doesn't have to be the user that is logged in, of course, but a user is needed anyway.

  1. Make a batch file (or equivalent) that works when you launch it manually
  2. Schedule the same batch file (with cmd /c c:\full\path\to\batch.bat) to run as yourself, with your password and everything.
  3. Now you are ready to debug your problem

The user Windows will use to run your task when no one is logged needs all the tools configured and working. For exemple, does local service have all the path and registry settings set ? Is the share readable by that user (the SYSTEM account does not have network credentials).

To help in debugging, use psexec. This command line will allow you to run your script under the SYSTEM account. Something like

psexec -dies cmd /c c:\full\path\to\batch.bat

+Welcome to SO !

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top