Hi,
Im currently in a situation to get all the application name that is currently running in windows but i can get only the processes that is currently running using the following code

Process p = Runtime.getRuntime().exec("tasklist.exe /v ");

Can anyone help me out in getting the application name...
Thanks in advance.

You need to parse the output of the tasklist, something like this:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class AppList {
	
	public static void main(String[] args) {
		try {
			Process p = Runtime.getRuntime().exec("tasklist.exe /FO LIST");
			BufferedReader in
			   = new BufferedReader(new InputStreamReader(p.getInputStream()));
			String str = in.readLine();
			while (str!=null) {
				if (str.startsWith("Image Name:")) {
					String appName = str.substring(11).trim();
					System.out.println(appName);
				}				
				str = in.readLine();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Thank for ur reply.but im getting only the exe files and im need of the application name.is anyother way to get the application name.

Thank for ur reply.but im getting only the exe files and im need of the application name.is anyother way to get the application name.

What do you mean by application name? If it is the Window Title, then you can change lines:
Line 10:

Process p = Runtime.getRuntime().exec("tasklist.exe /v /FO LIST");

Line 15-16:

if (str.startsWith("Window Title:")) {
String appName = str.substring(13).trim();

Hi zloiadun,
Thanks for ur help and i got the window title for the currently running applications and thank u very much for ur idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.