Java – Get task manager list via SWT
Is there a way using SWT to get a list of all processes currently running (similar to executing tasklist.exe/tlist.exe on Windows)? If so, is there sample code available?
Ideally this would be done programmatically only (no third party tools).
My app monitors the process list and needs to support Windows 2000/Server 2003/XP Home/XP Pro/Vista
Best Solution
This does not seem to be possible using SWT or even Java for that matter is a poor fit across multiple platforms. I ended up using JNI to list the running tasks. This works across all OS that I required. I found a good working example at the address below that I integrated into my app. Has multiple features implemented such as listing processes, killing processes, finding if specific EXE is running, and more. Hope this helps someone in the future.
Related Solutions
Java – Does a finally block always get executed in Java
Yes, finally will be called after the execution of the try or catch code blocks.
The only times finally won’t be called are:
- If you invoke System.exit()
- If you invoke Runtime.getRuntime().halt(exitStatus)
- If the JVM crashes first
- If the JVM reaches an infinite loop (or some other non-interruptable, non-terminating statement) in the try or catch block
- If the OS forcibly terminates the JVM process; e.g., kill -9 on UNIX
- If the host system dies; e.g., power failure, hardware error, OS panic, et cetera
- If the finally block is going to be executed by a daemon thread and all other non-daemon threads exit before finally is called
Java – How to get an enum value from a string value in Java
Yes, Blah.valueOf(«A») will give you Blah.A .
Note that the name must be an exact match, including case: Blah.valueOf(«a») and Blah.valueOf(«A «) both throw an IllegalArgumentException .
The static methods valueOf() and values() are created at compile time and do not appear in source code. They do appear in Javadoc, though; for example, Dialog.ModalityType shows both methods.
Related Question
Tasks API v1 (revision 71)
Clears all completed tasks from the specified task list. The affected tasks will be marked as ‘hidden’ and no longer be returned by default when retrieving all tasks for a task list. Create a request for the method «tasks.clear». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
delete
public Tasks.TasksOperations.Delete delete(java.lang.String tasklist, java.lang.String task) throws java.io.IOException
Deletes the specified task from the task list. Create a request for the method «tasks.delete». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
get
public Tasks.TasksOperations.Get get(java.lang.String tasklist, java.lang.String task) throws java.io.IOException
Returns the specified task. Create a request for the method «tasks.get». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
insert
public Tasks.TasksOperations.Insert insert(java.lang.String tasklist, Task content) throws java.io.IOException
Creates a new task on the specified task list. Fails with HTTP code 403 or 429 after reaching the storage limit of 100,000 tasks per account. Create a request for the method «tasks.insert». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
list
public Tasks.TasksOperations.List list(java.lang.String tasklist) throws java.io.IOException
Returns all tasks in the specified task list. Create a request for the method «tasks.list». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
move
public Tasks.TasksOperations.Move move(java.lang.String tasklist, java.lang.String task) throws java.io.IOException
Moves the specified task to another position in the task list. This can include putting it as a child task under a new parent and/or move it to a different position among its sibling tasks. Create a request for the method «tasks.move». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
patch
public Tasks.TasksOperations.Patch patch(java.lang.String tasklist, java.lang.String task, Task content) throws java.io.IOException
Updates the specified task. This method supports patch semantics. Create a request for the method «tasks.patch». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
update
public Tasks.TasksOperations.Update update(java.lang.String tasklist, java.lang.String task, Task content) throws java.io.IOException
Updates the specified task. Create a request for the method «tasks.update». This request holds the parameters needed by the tasks server. After setting any optional parameters, call the AbstractGoogleClientRequest.execute() method to invoke the remote operation.
(Java) Get all Tasks on a List
Demonstrates how to get all the tasks in a Google task list.
Chilkat Java Downloads
import com.chilkatsoft.*; public class ChilkatExample < static < try < System.loadLibrary("chilkat"); > catch (UnsatisfiedLinkError e) < System.err.println("Native code library failed to load.\n" + e); System.exit(1); > > public static void main(String argv[]) < // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Get the previously obtained access token. // See Get Google Tasks Access Token. CkFileAccess fac = new CkFileAccess(); String accessToken = fac.readEntireTextFile("qa_data/tokens/googleTasks.txt","utf-8"); if (fac.get_LastMethodSuccess() != true) < System.out.println(fac.lastErrorText()); return; > CkHttp http = new CkHttp(); http.put_AuthToken(accessToken); // Get the tasks from the task list w/ http.SetUrlVar("tasklist","MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzow"); CkHttpResponse resp = http.QuickGetObj("https://www.googleapis.com/tasks/v1/lists//tasks"); if (http.get_LastMethodSuccess() == false) < System.out.println(http.lastErrorText()); return; > // Show the response body. System.out.println(resp.bodyStr()); // Examine the response status code. System.out.println("response status code: " + resp.get_StatusCode()); // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON String kind; String etag; int i; int count_i; String id; String title; String updated; String selfLink; String position; String notes; String status; String due; CkJsonObject json = new CkJsonObject(); json.Load(resp.bodyStr()); kind = json.stringOf("kind"); etag = json.stringOf("etag"); i = 0; count_i = json.SizeOfArray("items"); while (i < count_i) < json.put_I(i); kind = json.stringOf("items[i].kind"); >stringOf("items[i].id"); etag = json.stringOf("items[i].etag"); title = json.stringOf("items[i].title"); updated = json.stringOf("items[i].updated"); selfLink = json.stringOf("items[i].selfLink"); position = json.stringOf("items[i].position"); notes = json.stringOf("items[i].notes"); status = json.stringOf("items[i].status"); due = json.stringOf("items[i].due"); i = i+1; > // Sample response: // // "kind": "tasks#tasks", // "etag": "\"84_7Cubo3y98GMV9bE3zQclHxhc/LTM3Njg4MjgyNA\"", // "items": [ // // "kind": "tasks#task", // "id": "MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzoyMDg3OTcyMDA1MTQ5NTA0", // "etag": "\"84_7Cubo3y98GMV9bE3zQclHxhc/NjcyMTU4Mg\"", // "title": "Get haircut", // "updated": "2019-04-04T18:07:58.000Z", // "selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzow/tasks/MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzoyMDg3OTcyMDA1MTQ5NTA0", // "position": "00000000001610612734", // "notes": "Check in online first.", // "status": "needsAction", // "due": "2019-04-07T00:00:00.000Z" // >, // // "kind": "tasks#task", // "id": "MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzoxMTg0MzQxMTkzMjM2MDY1", // "etag": "\"84_7Cubo3y98GMV9bE3zQclHxhc/MTU1MjQzNDIwMQ\"", // "title": "Go to grocery store", // "updated": "2019-04-04T17:59:15.000Z", // "selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzow/tasks/MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzoxMTg0MzQxMTkzMjM2MDY1", // "position": "00000000002147483647", // "notes": "Don't forget to buy apples.", // "status": "needsAction", // "due": "2019-04-07T00:00:00.000Z" // > // ] // > // // response status code: 200 > >
© 2000-2023 Chilkat Software, Inc. All Rights Reserved.