使用 Java 的 Windows 运行应用程序列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2206080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:53:26  来源:igfitidea点击:

Windows running application list using Java

windows

提问by Palanisami

How to get Windows running application list using Java?I got to get the processlist.

如何使用 Java 获取 Windows 运行应用程序列表?我必须获取进程列表。

回答by Philippe

I would recommend also using the qprocess utility, then, if you need more info about a process, use wmic.

我还建议使用 qprocess 实用程序,然后,如果您需要有关进程的更多信息,请使用 wmic。

Example :

例子 :

String line;
try {
        Process proc = Runtime.getRuntime().exec("wmic.exe");
        BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());
        oStream .write("process where name='explorer.exe'");
        oStream .flush();
        oStream .close();
        while ((line = input.readLine()) != null) {
            System.out.println(line);
        }
        input.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

See http://ss64.com/nt/wmic.htmlor http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.aspfor some example of what you can get from wmic...

请参阅http://ss64.com/nt/wmic.htmlhttp://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp了解您可以从 wmic 获得的一些示例...

回答by Rorick

You can run some command line util from Java for collecting processes information. For example:

您可以从 Java 运行一些命令行工具来收集进程信息。例如:

Process process = Runtime.getRuntime().exec("qprocess");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

Then you just read its output and parse it. qprocessis a standard Windows XP utility. In other versions of Windows you probably need some other utility.

然后你只需读取它的输出并解析它。qprocess是一个标准的 Windows XP 实用程序。在其他版本的 Windows 中,您可能需要一些其他实用程序。

回答by ghostdog74

you can search SO for similar answers. one here. See if it fits your needs. Else, there are many solutions on the net as well. search googlefor them

你可以搜索类似的答案。一个在这里。看看它是否符合您的需求。另外,网络上也有很多解决方案。用谷歌搜索他们

回答by Panchotiya Vipul

    package com.vipul;

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class BatchExecuteService extends Applet {
    public Choice choice;

    public void init() 
    {
        setFont(new Font("Helvetica", Font.BOLD, 36));
        choice = new Choice();
    }

    public static void main(String[] args) {
        BatchExecuteService batchExecuteService = new BatchExecuteService();
        batchExecuteService.run();
    }

    List<String> processList = new ArrayList<String>();

    public void run() {
        try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec("D:\server.bat");
            process.getOutputStream().close();
            InputStream inputStream = process.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(
                    inputStream);
            BufferedReader bufferedrReader = new BufferedReader(
                    inputstreamreader);
            BufferedReader bufferedrReader1 = new BufferedReader(
                    inputstreamreader);

            String strLine = "";
            String x[]=new String[100];
            int i=0;
            int t=0;
            while ((strLine = bufferedrReader.readLine()) != null) 
            {
        //      System.out.println(strLine);
                String[] a=strLine.split(",");
                x[i++]=a[0];
            }
    //      System.out.println("Length : "+i);

            for(int j=2;j<i;j++)
            {
                System.out.println(x[j]);
            }
        }
        catch (IOException ioException) 
        {
            ioException.printStackTrace();
        }

    }
}

you can create batch file like

您可以创建批处理文件,例如

TASKLIST /v /FI "STATUS eq running" /FO "CSV" /FI "Username eq LHPL002\soft" /FI "MEMUSAGE gt 10000" /FI "Windowtitle ne N/A" /NH

TASKLIST /v /FI "STATUS eq running" /FO "CSV" /FI "Username eq LHPL002\soft" /FI "MEMUSAGE gt 10000" /FI "Windowtitle ne N/A" /NH