*
The moose likes Java in General and the fly likes Running processes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running processes " Watch "Running processes " New topic
Author

Running processes

Kasun Liyanage
Greenhorn

Joined: Mar 09, 2011
Posts: 23

Hi

i need to create an app that iterate through each of currently running processes on the computer. i need to get a handle to each process, handle to each process's window--if it has one--and to read it's caption. i have created this type of thing with C++ but i don't have a clue of doing it with Java. How should i do this, what Java classes libs i should use for doing these system processes specific stuff.
I'll greatly appreciate ANY help.
Thanks!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Java is not very well suited for a task like that.

Java is designed to be cross-platform, so things that are very operating-system specific, such as enumerating the processes and finding window handles, cannot be easily done, because Java doesn't provide standard API methods to do very operating-system specific things like that.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
nishit charania
Greenhorn

Joined: Feb 10, 2010
Posts: 9
Hi

As much I am getting from your request you just need all process name which is ruing on windows system.
That you can get using some windows internal command like "tasklist" or "wmic process list".
This command you can execute using Runtime java api (http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html)
For more information about Runtime api check this link http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

One more solution is you have that c code that gives you all the needed details, modify it as a way that you can get input in java code when you execute that exe using Runtime api.
Or create dll out of your c program and and expose method to java code using JNI.

Good Luck
Kasun Liyanage
Greenhorn

Joined: Mar 09, 2011
Posts: 23

Thanks mates for the replies. Thought java was the god of coding langs Seems like i need to go back to C++ for certain things
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

It's always best to use the right tool for the job - and there is not a single tool which is perfect for all jobs. Java is great for many things, but not the best tool for very platform-specific things.
Kasun Liyanage
Greenhorn

Joined: Mar 09, 2011
Posts: 23

So, is it difficult/impossible too to write a program such as a wallpaper changer for windows/linux with java?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

On Linux you can usually call a command to do that. For Windows I don't know of any such command, so you'd have to use JNI.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Running processes
 
Similar Threads
Can you assign unique thread ids and access thread from external program?
Caution - Vague questions inside.
How to use 1 connection pool for multiple processes?
High volume data processing question
Messaging Architecture using Spring and ActiveMQ