Pregunta

how can I get a Process object by a certain ProcessId in Java.

I am using JNA to create a process, because I want to open a application in the background.

WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO();
startupInfo.dwFlags = 1;

WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReference();

Kernel32.INSTANCE.CreateProcess(null, "C:\\Program Files\\...", null, null, true, new WinDef.DWORD(0), Pointer.NULL, System.getProperty("java.io.tmpdir"), startupInfo, processInformation);

int prozessId = processInformation.dwProcessId.intValue();
¿Fue útil?

Solución

This isn't possible. The API for Process and ProcessBuilder don't allow you to create Process instances for existing processes; you can always only create new child processes with them.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top