This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Running processes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

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
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

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: 19214

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Running processes
 
Similar Threads
Messaging Architecture using Spring and ActiveMQ
Can you assign unique thread ids and access thread from external program?
Caution - Vague questions inside.
High volume data processing question
How to use 1 connection pool for multiple processes?