打开进程句柄 - KeOpenProcess
函数简介
打开指定进程的内核句柄,用于后续读写或控制等操作。
接口名称
KeOpenProcess
DLL调用
int32_t KeOpenProcess(int64_t instance, int64_t pid, int64_t* process_handle);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| pid | 长整数型 | 目标进程ID。 |
| process_handle | 长整数型指针 | 输出参数,返回打开的进程句柄。 |
示例
#include <stdio.h>
#include <stdint.h>
int main() {
int64_t ola = CreateCOLAPlugInterFace();
int64_t process_handle = 0;
int32_t ok = KeOpenProcess(ola, 1234, &process_handle);
printf("KeOpenProcess ok=%d, handle=%lld\n", ok, (long long)process_handle);
if (ok == 1 && process_handle != 0) {
// 使用完成后关闭句柄
CloseHandle(ola, process_handle);
}
DestroyCOLAPlugInterFace(ola);
return 0;
}
返回值
1 成功,其他失败。
注意事项
- 需要驱动支持与管理员权限。
- 打开成功后请在不再使用时调用
CloseHandle关闭句柄。 pid必须有效且对应的进程存在。
