vb 中OpenProcess的意思与常量
PROCESS_VM_READ = &H10&
PROCESS_VM_WRITE = &H20&这3个常量有什么用? GetWindowThreadProcessId hwnd, PId
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, PId)这又是什么意思? 展开
OpenProcess 函数用来打开一个已存在的进程,并返回进程的句柄。
方法名称:OpenProcess
位置:Kernel32.dll
OpenProcess 函数用来打开一个已存在的进程对象,并返回进程的句柄。
1.函数原型
HANDLE OpenProcess(
DWORD dwDesiredAccess, //渴望得到的访问权限(标志)
BOOL bInheritHandle, // 是否继承句柄
DWORD dwProcessId// 进程标示符
)
1.VB声明
Declare Function OpenProcessLib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
说明
打开一个现有进程的句柄
2.返回值
Long,如执行成功,返回进程句柄;零表示失败。会设置GetLastError
3.参数表
参数 类型 及 说明
dwDesiredAccess Long,指定这个句柄要求的访问方法。以下是常的常数
PROCESS_VM_OPERATION ‘操作进程内存空间的权限(可用VirtualProtectEx和WriteProcessMemory)
PROCESS_VM_READ’读取进程内存空间的权限,可用ReadProcessMemory
PROCESS_VM_WRITE‘读取进程内存空间的权限,可用WriteProcessMemory
bInheritHandle Long,如句柄能够由子进程继承,则为TRUE
dwProcessId Long,要打开那个进程的进程标识符
4.注解
这个函数经常用来打开一个要进行同步的进程(同步:即步调协同,你说完,我再说,按说好的先后次序来)
5.举例
Private Declare Function OpenProcess Lib "kernel32" (ByVal
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId
As Long) As Long
Private Declare Function ReadProcessMemory Lib
"kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As
Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '打开进程
If hProcess Then ReadProcessMemory hProcess, ByVal &H12F82C, base, 4, 0& '读写进程内存
CloseHandle hProcess '关闭进程句柄
End If
2013-09-10
PROCESS_VM_READ’读取进程内存空间的权限,可用ReadProcessMemory
PROCESS_VM_WRITE‘读取进程内存空间的权限,可用WriteProcessMemory