如何在任务管理器中打开/切换到进程

时间:2014-08-18 07:14:24

标签: process vb6 taskmanager

我试过google-ing但结果只是为了结束一个进程...我想从我的vb应用程序切换到另一个进程...

我目前正在使用AppActivate,但程序标题名称不是唯一的,所以我收到错误... 我可以使用*标志吗?

1 个答案:

答案 0 :(得分:0)

AppActivate Statement

激活应用程序窗口。

语法

AppActivate title[, wait]

AppActivate语句语法具有以下命名参数:

部分描述 title必需。字符串表达式,指定要激活的应用程序窗口的标题栏中的标题。 Shell函数返回的任务ID 可用于代替标题来激活应用程序。

使用WMI获取PID或Toolhelper库。

  Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
  Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
 Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long

 Private Declare Function GetVersionExA Lib "kernel32" _
     (lpVersionInformation As OSVERSIONINFO) As Integer



  Private Type PROCESSENTRY32
     dwSize As Long
     cntUsage As Long
     th32ProcessID As Long           ' This process
     th32DefaultHeapID As Long
     th32ModuleID As Long            ' Associated exe
     cntThreads As Long
     th32ParentProcessID As Long     ' This process's parent process
     pcPriClassBase As Long          ' Base priority of process threads
     dwFlags As Long
     szExeFile As String * 260 ' MAX_PATH
  End Type

  Private Type OSVERSIONINFO
     dwOSVersionInfoSize As Long
     dwMajorVersion As Long
     dwMinorVersion As Long
     dwBuildNumber As Long
     dwPlatformId As Long           '1 = Windows 95 2 = Windows NT
     szCSDVersion As String * 128
  End Type

   Private Const PROCESS_QUERY_INFORMATION = 1024
   Private Const PROCESS_VM_READ = 16
   Private Const MAX_PATH = 260
   Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
   Private Const SYNCHRONIZE = &H100000
  'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
   Private Const PROCESS_ALL_ACCESS = &H1F0FFF
   Private Const TH32CS_SNAPPROCESS = &H2&
   Private Const hNull = 0
   Private Const GW_CHILD = 5
   Private Const GW_HWNDNEXT = 2

Sub mnuInsertProcessList_Click()
         Dim f As Long, sname As String, PList As String, Ret As Long
         Dim hSnap As Long, proc As PROCESSENTRY32
         hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
         If hSnap = hNull Then Exit Sub
         proc.dwSize = LenB(proc)
         ' Iterate through the processes
         txtNote.SelText = "PID:int" & vbTab & "ParentPID:int" & vbTab & "ExeName:string" & vbCrLf
         f = Process32First(hSnap, proc)
         Do
                sname = StrZToStr(proc.szExeFile)
                txtNote.SelText = proc.th32ProcessID
                txtNote.SelText = vbTab
                txtNote.SelText = proc.th32ParentProcessID
                txtNote.SelText = vbTab
                 txtNote.SelText = sname
                txtNote.SelText = vbCrLf
                f = Process32Next(hSnap, proc)
         Loop While f = 1
        Ret = CloseHandle(hSnap)
        If Ret = 0 Then MsgBox Err.LastDllError
 End Sub