Micro Focus QTP (UFT) Forums
closing a process using QTP - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: closing a process using QTP (/Thread-closing-a-process-using-QTP)



closing a process using QTP - sunny rao - 08-15-2008

Hi all,

1)I want to check a process in task manager and close the application if the process is running.

2)I open explorer and am able to check the explorer.exe is running in the task manager using QTP.

3) next I want to delete the explorer.exe from the task manager. For that purpose I wrote the code below. when I execute it , all processes in the computer is killed, only QTP remains and I have to shut down and restart the PC. can anybody suggest how to kill the .exe file from the task manager.


Code:
Set process = GetObject("winmgmts")

Set allIExplorer = process.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'")

For Each IE in allIExplorer
    IE.Terminate()
Next



RE: closing a process using QTP - ashokghali - 08-22-2008

I tried the same code but it is closing only process explorer...Try the below code.

Code:
'Get the WMI object
Set WMI = GetObject("winmgmts:\\")

'Get collection of processes for with name iexplore.exe
Set allIE = WMI.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'")

'Loop through each process and terminate it
For Each IE in allIE
    IE.Terminate()
Next



RE: closing a process using QTP - Ankur - 08-22-2008

@sunny rao: There is a huge difference between explorer.exe and iexplore.exe. While the former refers to Windows explorer the latter is for Intenet Explorer and I believe it is the one you want to kill.

Never try to kill the explorer.exe which will for obvious reasons bring your system to stand still.

This code should work fine:
Code:
Set process = GetObject("winmgmts:\\")

Set allIExplorer = process.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'")

For Each IE in allIExplorer
IE.Terminate()
Next