Running a list of Windows applications using Java

How to get Windows to start the list of applications using Java? I need to get a list of processes.

+3
windows
Feb 05 '10 at 9:10
source share
4 answers

I would also recommend using the qprocess utility, then if you need more information about the process, use 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.html or http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp for some example of what you can get from wmic ...

+3
Feb 05 '10 at
source share

You can run some command line from Java to collect process information. For example:

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

Then you just read its conclusion and analyzed it. qprocess is a standard Windows XP utility. On other versions of Windows, you will probably need another utility.

+2
Feb 05 '10 at 9:24 a.m.
source share

you can search SO for similar answers. one here . See if it suits your needs. In addition, the network has many solutions. do a google search for them

0
Feb 05 '10 at 9:14
source share
  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 a batch file for example

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

0
May 30 '13 at 5:17
source share



All Articles