简体   繁体   中英

How to pass arguments from a java application to a windows Time Scheduler?

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 :

在此处输入图片说明

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

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.

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();
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM