Thursday, 20 February 2014

How to close all processes with given name in QTP?

While testing the applications with automation, we need to close existing applications and then start new one to avoid a clash.

Below example demonstrates how we can close all processes with given name.

Suppose if you want to close all excel processes, then you can use below code.
Call closeProcessByName("excel.exe")

Suppose if you want to close all internet explorer browser processes, then you can use below code.
Call closeProcessByName("iexplore.exe")

In similar way you can close any process given that you know the name of process

Sub closeProcessByName(byval process_name)

sComp = "."

'Get the WMI object
Set WMI = GetObject("winmgmts:\\" &  sComp &  "\root\cimv2")

'Get collection of processes with process_name like excel.exe, iexplore.exe

 Set allp = WMI.ExecQuery("Select * from Win32_Process Where Name = '" & process_name & "'")

'terminate each process
For Each p  in allp
p.Terminate()
Next 

End Sub


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.