Java 按进程Id获取进程对象

Java 按进程Id获取进程对象,java,winapi,process,jna,Java,Winapi,Process,Jna,在Java中,如何通过某个ProcessId获取流程对象 我正在使用JNA创建一个进程,因为我想在后台打开一个应用程序 WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO(); startupInfo.dwFlags = 1; WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReferenc

在Java中,如何通过某个ProcessId获取流程对象

我正在使用JNA创建一个进程,因为我想在后台打开一个应用程序

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();

这是不可能的。
Process
ProcessBuilder
的API不允许您为现有流程创建
Process
实例;始终只能使用它们创建新的子进程。

为什么不使用进程?如何在Java中不在后台打开进程?我已经尝试过了,但我的应用程序总是在前台启动。我使用ProcessBuilder来解决这个问题,我想这个问题与Windows API编程有关,而不是与Java有关!可能重复