我打开一个EXE文件后,怎么样在别一个进程里判断这个EXE的进程还在运行呢?
请指教

解决方案 »

  1.   

    用findwindow查hwnd,可以查出是否存在,QQ好象是3**** 多少吧。
    Option ExplicitPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Const SW_SHOWNORMAL = 1
    Const WM_CLOSE = &H10
    Const gcClassnameMSWord = "OpusApp"
    Const gcClassnameMSExcel = "XLMAIN"
    Const gcClassnameMSIExplorer = "IEFrame"
    Const gcClassnameMSVBasic = "wndclass_desked_gsk"
    Const gcClassnameNotePad = "Notepad"
    Const gcClassnameMyVBApp = "ThunderForm"
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
        'Ask for a Window title
        Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
        'Search the window
        WinWnd = FindWindow(vbNullString, Ret)
        If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
        'Show the window
        ShowWindow WinWnd, SW_SHOWNORMAL
        'Create a buffer
        lpClassName = Space(256)
        'retrieve the class name
        RetVal = GetClassName(WinWnd, lpClassName, 256)
        'Show the classname
        MsgBox "Classname: " + Left$(lpClassName, RetVal)
        'Post a message to the window to close itself
        PostMessage WinWnd, WM_CLOSE, 0&, 0&
    End Sub
      

  2.   

    要检测的EXE文件的路径、名字知道吧,用下面的办法取得进程ID对应的EXE文件,
    比较一下是不是同一个文件就知道了
    -----------------------------------------------------------------------------
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessID)  '获取进程句柄
        
        If hProcess <> 0 Then
            lRet = EnumProcessModules(hProcess, Modules(1), 255, cbNeeded2)
            
            
            If lRet <> 0 Then             
                ModuleName = Space(255) 
                nSize = 255
                lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, 255)
                'EXE文件路径、文件名
                strPath = LCase(Left(ModuleName, InStr(1, ModuleName, Chr(0)) - 1))
                
                '在这里比较是不是要判断的EXE文件        End If
        
        End If
        
        Call CloseHandle(hProcess)
      

  3.   

    知道进程的路径吗,如f:/dd.exe
      

  4.   

    用toolhelp32函数可以获得系统中进程对应的.exe文件的路径和文件名,遍历一下和要检测的.exe比较一下就行了。以下仅供参考:
    http://sanjianxia.myrice.com/vb/113.htm
      

  5.   

    遍历一下不如用OpenProcess来得直接。
      

  6.   

    但主要是得获得进程路径和文件名。(如果仅能用OpenProcess做到的话愿闻其详)
      

  7.   

    把Task ID传给那个“另一个程序”