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
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")
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