获取不到进程句柄 pHandle,请大侠帮帮忙,看哪里出问题了
大侠,看一下想获得QQ的进程句柄,为什么phandle总是得到0呢? 运行环境win7 32位旗舰版Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function writeprocessmemory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberofbyteswritten As Long) As Long
Private Declare Function readprocessmomory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberifbyteswritten As Long) As Long
Private Declare Function closehandle Lib "kernel32" (ByVal hobject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "QQ") '得到窗口句柄
Label3.Caption = hwnd
If hwnd = 0 Then
Label1.Caption = "程序未运行" '验证是否得到有效窗口句柄
Else
Label1.Caption = "程序已运行"
End If
Dim pid As Long
Dim pHandle As Long
GetWindowThreadProcessId hwnd, pid '得到进程标识符
Label2.Caption = pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '通过进程标识符获得进程句柄
If pHandle = 0 Then
MsgBox "couldn 't get a process handle!"
Else
Label4.Caption = pHandle
End If
End Sub
[此贴子已经被作者于2016-7-28 15:23编辑过]