954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get the application name that is currently running in windows

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.

sennat_26
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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();
		}
	}

}
zloiadun
Newbie Poster
3 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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.

sennat_26
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 
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();
zloiadun
Newbie Poster
3 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

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.

sennat_26
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You