'声明:
Public Const PROCESS_ALL_ACCESS& = &H1F0FFF
Public Const MEM_COMMIT = &H1000
Public Const PAGE_READWRITE = &H4
Public Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
**********************************************************************************
'代码:
Private Sub Command1_Click()
Dim PID As Long, hProcess As Long, hBlock As Long
PID =1234 '在Windows任务管理器里查看再填入
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
If hProcess = 0 Then
MsgBox "没有权限打开进程!", vbInformation
Exit Sub
End If
hBlock = VirtualAllocEx(hProcess, 0&, 1024, MEM_COMMIT, PAGE_READWRITE)
If hBlock = 0 Then
MsgBox "无法分配内存空间!", vbInformation
Exit Sub
End If