1

I want to pass arguments to Windows Time Scheduler using java application

So i open Scheduler

public static void main(String[] args) { 
Runtime.getRuntime().exec("cmd /c " + "%windir%\\system32\\taskschd.msc /s");

Now create a simple task . How can i pass arguments programmatically :

enter image description here

For example i need to pass the following

  • Program script: C:\Program Files\Java\jre7\bin\java.exe
  • Add arguments: -jar c:\abc\ab.jar
  • Start in: c:\abc
Andrei Vasilev
  • 597
  • 5
  • 18
  • 37

3 Answers3

2

Don't do it through cmd (command - line). Use ITaskService COM interface for managing tasks (create, modify, delete). In Java use Com4J interface to Windows COM.

But if you still would like to use command - line, use Windows Powershell for this.

Last way to do this is to create Task Scheduler XML-based file (in Java). Those are XML-s conforming to the Task Scheduler Schema and are stored in %SystemRoot%\Tasks or %SystemRoot%\System32\Tasks.

Create code is up to you, especially creating .xml with windows task is quick-and-easy for simple test. Hope this will help.

1ac0
  • 2,875
  • 3
  • 33
  • 47
1

Sorry I don't fully understand the question, but I tried my best. This works for me.

    try {
        Runtime.getRuntime().exec("java -jar c:\application.jar args");
    }
    catch(IOException e) {
        e.printStackTrace();
    }
codewiz
  • 196
  • 1
  • 8
1

You can use Schtasks command line utility to add tasks. Also, see this question about specifying start folder: Specifying "start-in" directory in schtasks command in windows

Community
  • 1
  • 1
Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68