Java JNA-如何通过.exe获取processID
因此,我使用“findWindow”atm来获取processID,但假设不是使用find window来获取“任务调用黑操作”,而是直接获取进程名为“BlackOps.exe”的processID。我该怎么做?这是我用java查找进程id的代码”Java JNA-如何通过.exe获取processID,java,c++,jna,Java,C++,Jna,因此,我使用“findWindow”atm来获取processID,但假设不是使用find window来获取“任务调用黑操作”,而是直接获取进程名为“BlackOps.exe”的processID。我该怎么做?这是我用java查找进程id的代码” #使用 使用名称空间系统; 使用名称空间系统::诊断; 使用名称空间System::ComponentModel; int main() { //获取当前进程。 进程^currentProcess=Process::GetCurrentProc
#使用
使用名称空间系统;
使用名称空间系统::诊断;
使用名称空间System::ComponentModel;
int main()
{
//获取当前进程。
进程^currentProcess=Process::GetCurrentProcess();
//在本地计算机上运行所有进程。
数组^localAll=Process::GetProcesses();
//获取本地计算机上运行的所有记事本实例。
//如果记事本没有运行,这将返回一个空数组。
数组^localByName=Process::GetProcessesByName(“记事本”);
//使用进程id在本地计算机上获取进程。
//如果没有这样的进程,这将引发异常。
进程^localById=Process::GetProcessById(1234);
//获取在远程计算机上运行的进程。请注意
//以下所有调用都将超时并引发异常
//如果本地网络上不存在“myComputer”和169.0.0.0。
//获取远程计算机上的所有进程。
数组^remoteAll=Process::GetProcesses(“myComputer”);
//使用计算机名获取在特定计算机上运行的所有记事本实例。
数组^remoteByName=Process::GetProcessByName(“记事本”、“myComputer”);
//使用IP地址获取在特定计算机上运行的所有记事本实例。
数组^ipByName=Process::GetProcessesByName(“记事本”、“169.0.0.0”);
//使用进程id和计算机名在远程计算机上获取进程。
进程^remoteById=Process::GetProcessById(2345,“myComputer”);
}
上面的代码是由microsoft自己编写的,您可以在此处看到完整答案:
这没有给出正确的进程ID,我正在使用作弊引擎进行检查。但这不是java
public static void main(String[] args) {
String taskListCommand = System.getenv("windir") + "\\system32\\" + "tasklist.exe";
try {
final Process p = Runtime.getRuntime().exec(taskListCommand);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
try {
while ((line = input.readLine()) != null) {
if (line.contains("BlackOps.exe")) {
System.out.println(line);
PID = (line.split("\\s+"))[1];
System.out.println("PID = " + PID);
break;
}
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
#using<System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
int main()
{
// Get the current process.
Process^ currentProcess = Process::GetCurrentProcess();
// Get all processes running on the local computer.
array<Process^>^localAll = Process::GetProcesses();
// Get all instances of Notepad running on the local computer.
// This will return an empty array if notepad isn't running.
array<Process^>^localByName = Process::GetProcessesByName("notepad");
// Get a process on the local computer, using the process id.
// This will throw an exception if there is no such process.
Process^ localById = Process::GetProcessById(1234);
// Get processes running on a remote computer. Note that this
// and all the following calls will timeout and throw an exception
// if "myComputer" and 169.0.0.0 do not exist on your local network.
// Get all processes on a remote computer.
array<Process^>^remoteAll = Process::GetProcesses("myComputer");
// Get all instances of Notepad running on the specific computer, using machine name.
array<Process^>^remoteByName = Process::GetProcessesByName( "notepad", "myComputer" );
// Get all instances of Notepad running on the specific computer, using IP address.
array<Process^>^ipByName = Process::GetProcessesByName( "notepad", "169.0.0.0" );
// Get a process on a remote computer, using the process id and machine name.
Process^ remoteById = Process::GetProcessById( 2345, "myComputer" );
}