VB中为什么用openprocess 返回进程句柄总是失败?
PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsStrin...
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Sub Command1_Click()
Dim k As Long
Dim WTP As Long
Dim op As Long
k = FindWindow(vbNullString, "计算器")
If k = 0 Then
MsgBox " 未找到窗口", 48, "提示"
Else
MsgBox "找到窗口,请确认", 48, "提示"
WTP = GetWindowThreadProcessId(k, vbNull)
If WTP = 0 Then
MsgBox "提取进程ID错误", 48, "提示"
Else
MsgBox "提取进程ID正确", 64, "提示"
op = OpenProcess(PROCESS_ALL_ACCESS, False, WTP)
If op = 0 Then
MsgBox "返回句柄失败", 48, "提示"
Else
MsgBox "返回句柄成功", 64, "提示"
End If
End If
End If
End Sub 展开
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Sub Command1_Click()
Dim k As Long
Dim WTP As Long
Dim op As Long
k = FindWindow(vbNullString, "计算器")
If k = 0 Then
MsgBox " 未找到窗口", 48, "提示"
Else
MsgBox "找到窗口,请确认", 48, "提示"
WTP = GetWindowThreadProcessId(k, vbNull)
If WTP = 0 Then
MsgBox "提取进程ID错误", 48, "提示"
Else
MsgBox "提取进程ID正确", 64, "提示"
op = OpenProcess(PROCESS_ALL_ACCESS, False, WTP)
If op = 0 Then
MsgBox "返回句柄失败", 48, "提示"
Else
MsgBox "返回句柄成功", 64, "提示"
End If
End If
End If
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询