please I want to recover the windows's process with java how can I do thank

Dani AI

Generated

asked to "recover the windows's process" — that wording is ambiguous. correctly asked for clarification, and guessed a Task‑Manager style list. Common interpretations and practical options are listed below so the likely goals (enumerate processes, inspect details, restart/kill) can be implemented reliably.

For modern Java (9+), the built‑in ProcessHandle API is the simplest cross‑platform way to enumerate processes and read available info (PID, command, args, CPU time). Example (trimmed):

ProcessHandle.allProcesses()
  .forEach(ph -> {
    ProcessHandle.Info info = ph.info();
    System.out.printf("PID=%d CMD=%s ARGS=%s CPU=%s%n",
      ph.pid(),
      info.command().orElse(""),
      Arrays.toString(info.arguments().orElse(new String[0])),
      info.totalCpuDuration().map(Duration::toString).orElse(""));
  });

On older JVMs or for quick Windows‑only scripts, invoke the system tool and parse output (works without native code). Example:

Process p = new ProcessBuilder("tasklist","/fo","csv","/nh").start();
try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
  String line;
  while ((line = r.readLine()) != null) {
    // parse CSV: "Image Name","PID","Session Name","Session#","Mem Usage"
  }
}

For Windows‑specific needs (owner, full command line reliably, low‑level process attributes, or manipulating another process), use a native bridge: JNA/JNI or WMI. JNA simplifies calling Win32 APIs; see JNA project. Notes: some fields may be empty for system processes or without admin rights; parsing localized tasklist output can break on non‑English systems; processes may exit mid‑enumeration — handle Optionals and exceptions. If the intent was to "recover" meaning restart or attach a debugger, that requires different tooling (ProcessBuilder for relaunch, or a native debugger for live inspection).

Recommended Answers

All 2 Replies

You'll have to rephrase the question. As stated, it's not clear at all what you are wanting to do.

i imagine he wants to get a list of all the processes running, like task manager?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.