How to get a list of current open windows/process with Java?

后端 未结 14 1363
抹茶落季
抹茶落季 2020-11-22 05:20

Does any one know how do I get the current open windows or process of a local machine using Java?

What I\'m trying to do is: list the current open task, windows or

14条回答
  •  别那么骄傲
    2020-11-22 05:54

    The only way I can think of doing it is by invoking a command line application that does the job for you and then screenscraping the output (like Linux's ps and Window's tasklist).

    Unfortunately, that'll mean you'll have to write some parsing routines to read the data from both.

    Process proc = Runtime.getRuntime().exec ("tasklist.exe");
    InputStream procOutput = proc.getInputStream ();
    if (0 == proc.waitFor ()) {
        // TODO scan the procOutput for your data
    }
    

提交回复
热议问题