vb 中OpenProcess的意思与常量
答案:2 悬赏:40 手机版
解决时间 2021-04-17 04:53
- 提问者网友:焚苦与心
- 2021-04-16 18:04
vb 中OpenProcess的意思与常量
最佳答案
- 五星知识达人网友:深街酒徒
- 2021-04-16 19:38
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
方法名称: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
全部回答
- 1楼网友:往事埋风中
- 2021-04-16 19:52
OpenProcess 函数用来打开一个已存在的进程,并返回进程的句柄。 上面的几个常量是访问方法,方法不一样权限就不一样PROCESS_VM_OPERATION ‘操作进程内存空间的权限(可用VirtualProtectEx和WriteProcessMemory)
PROCESS_VM_READ’读取进程内存空间的权限,可用ReadProcessMemory
PROCESS_VM_WRITE‘读取进程内存空间的权限,可用WriteProcessMemory
PROCESS_VM_READ’读取进程内存空间的权限,可用ReadProcessMemory
PROCESS_VM_WRITE‘读取进程内存空间的权限,可用WriteProcessMemory
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯