I am using Scala and I couldn't find something that would give me the PrcoessID from the Processname. Neither in Java, Scala or Winapi.
At the moment I am using FindWindowA
and GetWindowThreadProcessId
, but I would prefer something that would give me an array
val process: Array[Int] = GetProcessIdFromExeName("Notepad")
So if I would have 10 instances of Notepad, I could access them with process(0-9)
I know that something like this exists in .NET, but is there something similar in the WINAPI or Java/Scala?
The simplest way is to run tasklist
and parse the output. See this resource for reference:
You can also use WMI. It is very simple to write JScript or VBScript that performs WMI query and prints the output, So you can run it from either java or Scala process and parse the output. WMI provides more options than tasklist
.
If you choose WMI you can also call it utilizing one of existing java-to-com libraries e.g. JaWin, Jintegra, JInterop.