按进程ID获取进程对象

时间:2014-01-14 12:56:39

标签: java winapi process jna

如何通过Java中的某个Process Id获取Process对象。

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

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

1 个答案:

答案 0 :(得分:1)

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

相关问题