Quick test professional

QTP Tips QTP codes QTP Faqs and more

How to Close QTP after execution

How to Close QTP after execution 

Private Function CloseQTP        

    Set objWMIService = GetObject(“winmgmts:\\.\root\CIMV2”)     

       Set colProcess = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘QTPro.exe'”)     

       For Each objProcess in colProcess                      



  Set objWMIService = Nothing         

   Set colProcess = NothingEnd FunctionCall CloseQTP

  Source: Mercury Forum’s KB articles



February 14, 2008 - Posted by | Automation Object Model For QTP | , , , , ,


  1. Hi Mohan,

    Interesting topic !

    I have a few questions on this :

    1. Let’s say you are running a test through QTP and you are done with it. After that When you query against Winmgmts object and terminate it. That will terminate the execution right at that point. Now what happens of the unreleased objects ? ( objWMIService and colProcess ) How does this work ?

    2. If I happen to have more than one QTPro.exe threads running on the same machine, does this work ? This is very strange but I do have come across this scenario. My question here is does this just work once ?

    3. I was testing a similar condition against a Citrix server ( for Excel ) and this did not work right , my condition was : a different user was logged on the citrix server already and disconnected it later, and left Excel open in THAT session. The code resulted in failing as it was finding an open process when queried, but failed while trying to close it !

    Does this method of closing have any other impacts like that ?

    I’d be glad if you could give your inputs on this.


    Comment by abhijeet | January 20, 2010 | Reply

    • nice question 🙂

      Comment by prateek gupta | February 25, 2014 | Reply

  2. Very useful for my VBS of run QTP.

    Comment by Hagai | May 20, 2010 | Reply

  3. how can we close QTP or stop the test if the user is in the recovery scenario. I dont want the stop run in post recovery. Since I want to close QTP is it is the last row of data or else continue.

    I have already tried exitaction, exittest, exittestiteration

    can u help

    Comment by divya | October 8, 2010 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: