Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
      On Error GoTo Err
      Dim WMI
      Dim Obj
      Dim Objs
      CheckApplicationIsRun = False
      Set WMI = GetObject("WinMgmts:")
      Set Objs = WMI.InstancesOf("Win32_Process")
      For Each Obj In Objs
               If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
                     CheckApplicationIsRun = True
                     If Not Objs Is Nothing Then Set Objs = Nothing
                     If Not WMI Is Nothing Then Set WMI = Nothing
                     Exit Function
               End If
      Next
      If Not Objs Is Nothing Then Set Objs = Nothing
      If Not WMI Is Nothing Then Set WMI = Nothing
      Exit Function
Err:
      If Not Objs Is Nothing Then Set Objs = Nothing
      If Not WMI Is Nothing Then Set WMI = Nothing
   End FunctionPrivate Sub Command1_Click()
If CheckApplicationIsRun("Main.exe") = True Then
SendKeys "%{TAB}"

Else
Shell "C:\Main.exe"
End If
End Sub能够判断进程存不存在,但是为什么他不能执行sendkeys呀。
(因为我只是想让main.exe进程存在的时候重新获得焦点。类似于alt+tab。)