I know that this questioned has been asken an umpteen number of times and its solution is also available but here is the twist:
1. I want to list the processes from the other OS as well. Like we can execute tasklist.exe using PrecessBuilder class but how about showing processes running on a Mac machine or on a Linux machine for that matter.
2. Also I would like to go a step further in a sense that I want to have the feature "bring to front" in the task manager. That will bring the selected window to the front.
I guess that for my second question I'll have to use JNI. Can some body tell me how can I accomplist the task. Or should i ask this way- is it even possible?
Joined: Mar 22, 2005
For #1, the "ps" command is available on all Unix-based OSes. "ps a" includes all foreground applications, but it lists more processes than just those. So you may have to do some filtering of the list.
I'll try to use ps command and will let you know if I stuck any where.
For the second one, do I need to call that function using JNI? Also I will have to get the process ID of the process which is selected and then use that to bring the window related to that process to the front. How can I do that?
If you are only worried about the windows opened by your Java application, you can use Window.getWindows() to retrieve all windows, then use the toFront() method of Window.
If you want all windows present, then you'll have to go JNI again. The functions involved are:
- a callback function you wrote: BOOL CALLBACK XXX(HWND hwnd, LPARAM lParam) (the XXX is free to fill in)
- inside that callback function, IsWindowVisible to see if the window is not hidden and GetWindowText to get the caption / title
Edit: if you have the process ID, you can use the following instead of EnumWindows:
There may be other ways I don't know of to get all threads of a process to replace the call to GetCurrentThreadId.