| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 601 人关注过本帖
标题:pid 在任务管理器看不到了 openprocess 为什么还返回非0?
只看楼主 加入收藏
czb27111111
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2015-2-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:9 
pid 在任务管理器看不到了 openprocess 为什么还返回非0?
R T
搜索更多相关主题的帖子: 任务管理器 
2015-08-01 22:10
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:0 
给个例子好不?正常情况下,手动杀死进程后再用api刷新是看不到该进程的。

能编个毛线衣吗?
2015-08-03 10:36
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
回复 楼主 czb27111111
在任务管理器中能不能看到PID是和"查看"中的"选择列"设置有关.
分没分配序号是和进程存不存在有关。

大开眼界
2015-08-03 10:52
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
广告是  神马北风网 还是北方网

DO IT YOURSELF !
2015-08-03 11:15
czb27111111
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2015-2-10
收藏
得分:0 
有一个数组,储存着SHELL函数的返回值。
SHELL运行一个程序,运行完后会自动退出。
用一个TIMER检测程序是否退出了
我判断OPENPROCESS(process_all_access,false,数组中的一个数)是否为零来判断程序是不是退出了
可当程序运行完后openprocess还是返回非零的数
2015-08-04 13:29
czb27111111
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2015-2-10
收藏
得分:0 
回复 2楼 wmf2014
用api刷新?
2015-08-04 13:34
czb27111111
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2015-2-10
收藏
得分:0 
回复 2楼 wmf2014
用API刷新?
2015-08-04 13:36
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
试试这个
程序代码:
Const SYNCHRONIZE = &H100000
'一直等待
Const INFINITE = &HFFFF

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Sub Command1_Click()
  Dim lPid As Long
  Dim lHnd As Long
  Dim lRet As Long
  lPid = Shell("notepad.exe", vbNormalFocus)
  If lPid <> 0 Then
    lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
    If lHnd <> 0 Then
      lRet = WaitForSingleObject(lHnd, INFINITE)
      CloseHandle (lHnd)
    End If
    MsgBox "已终止.", vbInformation, "Shelled Application"
  End If
End Sub


大开眼界
2015-08-04 15:18
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:20 
程序代码:
Option Explicit

Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetProcessTimes Lib "kernel32" (ByVal hProcess As Long, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

  Dim c As FILETIME
  Dim e As FILETIME
  Dim k As FILETIME
  Dim u As FILETIME
  Dim lPid As Long
  Dim lHnd As Long
  Dim lRet As Long

Private Sub Command1_Click()

  lPid = Shell("notepad.exe", vbNormalFocus)
  If lPid <> 0 Then
    lHnd = OpenProcess(PROCESS_ALL_ACCESS, 0, lPid)
    Form1.Caption = lHnd
    Timer1.Enabled = True
  End If
End Sub

Private Sub Timer1_Timer()
  Dim temp As Long
  temp = GetProcessTimes(lHnd, c, e, k, u)
  Text1.Text = temp & "," & e.dwHighDateTime & "," & e.dwLowDateTime
  If e.dwHighDateTime <> 0 Or e.dwLowDateTime <> 0 Then
    Form1.Caption = "完成"
    CloseHandle lHnd
    Timer1.Enabled = False
  End If
End Sub
也可以这样

大开眼界
2015-08-04 15:29
czb27111111
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2015-2-10
收藏
得分:0 
回复 9楼 lianyicq
谢谢,我用
程序代码:
    If TheProcesses(0) <> 0 Then
        Dim i As Long
        For i = UBound(TheProcesses) To 0 Step -1
            Dim a As Long
            a = OpenProcess(PROCESS_ALL_ACCESS, False, TheProcesses(i))
            If a = 0 Then
                Call DeleteFormArray(TheProcesses, i)
            Else
                Dim CreationTime As FileTime, ExitTime As FileTime, KernelTime As FileTime, UserTime As FileTime
                If GetProcessTimes(a, CreationTime, ExitTime, KernelTime, UserTime) = 0 Then
                    MsgBox GetLastError
                    Call DeleteFormArray(TheProcesses, i)
                Else
                    If ExitTime.dwHighDateTime <> 0 And ExitTime.dwLowDateTime <> 0 Then
                        Call DeleteFormArray(TheProcesses, i)
                    End If
                End If
            End If
            Call CloseHandle(a)
        Next i
    End If

解决了
2015-08-08 10:37
快速回复:pid 在任务管理器看不到了 openprocess 为什么还返回非0?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030627 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved