QTP中如何判断Excel进程是否存在?

来源:互联网 发布:bt4破解软件下载 编辑:程序博客网 时间:2024/04/30 10:22

如何判断Excel进程是否存在?如果存在则关闭Excel进程。

 

 

SystemUtil.CloseProcessByName "excel.exe"

 

On error resume next

  Dim Obj

  Set Obj = GetObject(,"Excel.Application")

  If Not Obj Is Nothing Then      

  Obj.Quit     

  Set Obj = Nothing

End If

 

或者:

' To kill excel application

CreateObject("WScript.Shell").Run "taskkill /f /im excel.exe"

 

'To check if excel is running use this function

msgbox "Excel is Running:" & FindProcess("EXCEL.EXE")

 

Function FindProcess(ByVal ProcessName)

  FindProcess= False   

  Set Shell = CreateObject("WScript.Shell")       

  Set ShellResult = Shell.Exec("TaskList")         

  While Not ShellResult.StdOut.AtEndOfStream         

    If Instr(UCASE(ShellResult.StdOut.ReadLine),UCASE(ProcessName)) Then

      FindProcess = True                

      Exit Function              

    End If         

  Wend  

End Function

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Testing_is_believing/archive/2010/04/18/5499698.aspx