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
展开
 我来答
wangtingze2008
2011-12-05 · TA获得超过400个赞
知道小有建树答主
回答量:839
采纳率:50%
帮助的人:377万
展开全部
可能是没开计算器进程。
可能是没有权限,不能打开另外的进程。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式