如何使用Java运行Windows运行应用程序列表?我得到了进程列表。
答案 0 :(得分:3)
我建议也使用qprocess实用程序,然后,如果您需要有关进程的更多信息,请使用wmic。
示例:
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();
}
请参阅http://ss64.com/nt/wmic.html或http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp了解您可以从wmic获得的一些示例......
答案 1 :(得分:2)
您可以从Java运行一些命令行util来收集进程信息。例如:
Process process = Runtime.getRuntime().exec("qprocess");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
然后你只需读取它的输出并解析它。 qprocess
是标准的Windows XP实用程序。在其他版本的Windows中,您可能需要一些其他实用程序。
答案 2 :(得分:0)
答案 3 :(得分:0)
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();
}
}
}
您可以创建像
这样的批处理文件TASKLIST / v / FI“STATUS eq running”/ FO“CSV”/ FI“用户名eq LHPL002 \ soft”/ FI“MEMUSAGE gt 10000”/ FI“Windowtitle ne N / A”/ NH